如果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