【发布时间】:2017-04-27 04:46:09
【问题描述】:
我有 3 个对话框,有一个 InitialDialog、StepOneDialog,最后是一个 EndDialog。每个 Dialog 通过执行以下操作来调用它的子级:
await context.Forward(dialog, ResumeAfter, new Activity { }, CancellationToken.None);
这在本地完美运行,但是当我发布它时出现问题。它只是陷入了一个循环,我认为这是因为对话框没有正确退出。 InitialDialog 继承了 LuisDialog。 我有以下方法之一的代码:
[LuisIntent("")]
public async Task None(IDialogContext context, LuisResult result)
{
// Create our response
var response = $"Sorry I did not understand your question.";
// Post our response back to the user
await context.PostAsync(response);
// Exit the application
context.Done(this);
}
如您所见,我调用context.Done(this) 来退出对话框,但我不确定这是否正确。在其他示例中,他们似乎使用context.Wait(MessageReceived);
我的其他对话框实现了IDialog<object>,因此我无法调用MessageReceived。所以在那种情况下,我设置了一个这样的方法:
private async Task ResumeAfter(IDialogContext context, IAwaitable<object> result) => context.Done(this);
我这样调用:
private async Task GetAnswer(IDialogContext context, IAwaitable<string> result)
{
// Get our quest
var questions = _group.Questions;
var length = questions.Count;
var question = _group.Questions[_currentQuestion];
var selectedAnswer = await result;
// Assign our answer to our question
foreach (var answer in question.Answers)
if (answer.Text == selectedAnswer)
question.Answer = answer;
// If we have an answer, filter the products
if (question.Answer != null)
_productProvider.Score(await GetCurrentProducts(), _groups);
// Increase our index
_currentQuestion++;
// If our current index is greater or equal than the length of the questions
if (_currentQuestion == length)
{
// Create our dialog
var dialog = _dialogFactory.CreateSecondStepDialog(_dialogFactory, _groupProvider, _questionProvider, _productProvider, await GetCurrentProducts());
// Otherwise, got to the next step
await context.Forward(dialog, ResumeAfter, new Activity { }, CancellationToken.None);
return;
}
// Ask our next question
await AskQuestion(context, null);
}
如您所见,context.Forward 将方法作为 Delegate 传递,并在子 Dialog 创建后执行。
有人可以告诉我我这样做是否正确吗?或者,如果我需要更改某些内容。
【问题讨论】:
-
不同意重复:这里用户不是在寻找孤子以关键字退出,应该通过正常的对话行为来完成
标签: c# botframework