如果 FormFlow 过于严格,您应该考虑使用 Dialogs。它们允许进行更开放的对话。
我会做以下事情:
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)在对话框中提问
在 Dialog 中,使用 PromptDialog 来询问问题 1。使用问题 1 的答案的开关来确定要问问题 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 语句来确定接下来要问什么问题。
单击此处了解有关对话框的更多信息