如果FormFlow過於嚴格,您應該考慮使用對話框。他們允許進行更開放的對話。
我會做到以下幾點:
1)讓用戶選擇一個類別。
如果可能,請使用按鈕爲用戶提供可供選擇的類別列表。這意味着您不必向LUIS詢問用戶選擇的類別。
否則,允許用戶鍵入一個類別並將其傳遞給LUIS。來自LUIS的回覆將包含一個實體。該實體將持有該類別的名稱。
2)轉發到對話框該類別
取決於實體從LUIS返回,前進到相應的對話框,這將是負責又問了一個問題
[LuisIntent("AskQuestionAboutCategory")]
public async Task AskQuestion(IDialogContext context, LuisResult result)
{
//get Entity from LUIS response
string category = result.Entities.FirstOrDefault(e => e.Type == "Category")?.Entity;
switch (category)
{
case "Category 1":
//forward to Dialog for Category1
await
context.Forward(new Category1Dialog(), ResumeAfter,
new Activity {Text = result.Query}, CancellationToken.None);
break;
case "Category 2":
//forward to Dialog for Category2
await
context.Forward(new Category2Dialog(), ResumeAfter,
new Activity {Text = result.Query}, CancellationToken.None);
break;
}
}
private async Task ResumeAfter(IDialogContext context, IAwaitable<object> result)
{
context.Wait(MessageReceived);
}
3)在對話框中提問問題
在對話框中,使用PromptDialog問問題1.對問題1的答案使用開關,將d確定要問什麼問題2. 繼續像這樣的對話。
[Serializable]
public class Category1Dialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
}
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
var prompt = "what is the answer to question 1 ?";
//ASK QUESTION 1
PromptDialog.Text(context, ResumeAfterQuestion1, prompt);
}
private async Task ResumeAfterQuestion1(IDialogContext context, IAwaitable<string> result)
{
var input = await result;
switch (input)
{
//ASK QUESTION 2, DEPENDING ON WHAT WAS ANSWERED FOR QUESTION 1
case "Answer A":
PromptDialog.Text(context, ResumeAfterQuestion2, "what is the answer to question 2 ?");
break;
case "Answer B":
PromptDialog.Text(context, ResumeAfterQuestion2, "what is the answer to question 2 ?");
break;
}
}
private async Task ResumeAfterQuestion2(IDialogContext context, IAwaitable<string> result)
{
var input = await result;
switch (input)
{
//ASK QUESTION 3
case "Answer C":
PromptDialog.Text(context, ResumeAfterQuestion3, "what is the answer to next question after Answer C ?");
break;
case "Answer D":
PromptDialog.Text(context, ResumeAfterQuestion3, "what is the answer to next question after Answer D ?");
break;
}
}
看起來您需要使用switch語句來確定接下來要問的問題。
click here for more info on Dialogs
這就是我需要的 – r3plica
這不是工作:(向前永不會向MessageReceivedAsync – r3plica
這是工作,似乎有是3.2.1中的一個bug – r3plica