问题描述
我实现了一个首先启动QnA对话框的结构.如果QnA对话框无法解决问题,则它将启动Luis对话框,该对话框已定义了一些主要功能.基于这些主要功能,我启动了可以解决问题的特定对话框.
I have implemented a structure where a QnA dialog is first started. If the QnA Dialog cannot solve the problem then it starts a Luis Dialog which has some main functionalities defined. Based on those main functionalities I start specific dialogs that can solve the problem.
我的问题是,当我尝试从QnAMaker启动LuisDialog时,它会启动另一个LuisDialog进行对话,该对话框不会在使用wait方法时停止,并在执行后立即自动调用ResumeAfter方法.
My problem is that when I try to start LuisDialog from QnAMaker, it starts another LuisDialog to for conversation, That dialog doesn't stop on with wait method and automatically calls ResumeAfter method immediately after executing.
QnADialog:
QnADialog:
protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResults results)
{
if (results == null || results.Answers.Count==0 || !IsConfidentAnswer(results) || results.Answers.FirstOrDefault().Score<0.75) {
await context.Forward(new MainLuisDialog(), MessageReceived, context.Activity.AsMessageActivity(), CancellationToken.None);
}
}
第一个Luis对话框:
First Luis Dialog:
[LuisIntent(ErrorFileLink)]
public async Task ErrorFileLinkIntentHandler(IDialogContext context, LuisResult result) {
await context.Forward(new ErrorFileLinkDialog(), CallBackHandler, context.Activity.AsMessageActivity(), CancellationToken.None);
}
private async Task CallBackHandler(IDialogContext context, IAwaitable<object> result)
{
try {
var returnedResult = await result;
if (returnedResult as string == "done")
context.Done(false);
}
catch (Exception e) {
}
}
第二个路易斯对话框:
[LuisIntent(MainAppIntent)]
public async Task MainAppIntentHandler(IDialogContext context, LuisResult result)
{
if(context.GetPrivateConversationData<SyncIssueStates>(CurrentDialogState) == SyncIssueStates.ExpectingSyncCompleteMessage)
{
await context.PostAsync(Utility.GetResourceString("SYNC_ISSUE_PLEASE_WAIT_SYNC_COMPELTE"));
context.Wait(MessageReceived);
return;
}
await context.PostAsync(Utility.GetResourceString("SYNC_ISSUE_GET_ERROR_MESSAGE"));
context.SetPrivateConversationData(CurrentDialogState, SyncIssueStates.ExpectingErrorMessage);
context.Wait(MessageReceived);
}
执行前进"后立即调用第一个Luis对话框"中的CallBackHandler方法.
CallBackHandler Method in First Luis Dialog is called right after Forward is executed.
推荐答案
我认为此行为是由于 QnAMakerDialog 在 DefaultWaitNextMessageAsync 内部调用context.Done(true);
造成的方法.参考: https://github.com/Microsoft/BotBuilder-CognitiveServices/blob/master/CSharp/Library/QnAMaker/QnAMaker/QnAMakerDialog.cs#L203
I think this behavior is due to the fact that the QnAMakerDialog calls context.Done(true);
inside the DefaultWaitNextMessageAsync method. ref: https://github.com/Microsoft/BotBuilder-CognitiveServices/blob/master/CSharp/Library/QnAMaker/QnAMaker/QnAMakerDialog.cs#L203
尝试改写 DefaultWaitNextMessageAsync 方法:
protected override async Task DefaultWaitNextMessageAsync(IDialogContext context, IMessageActivity message, QnAMakerResults results)
{
if (results == null || results.Answers.Count == 0 || !IsConfidentAnswer(results) || results.Answers.FirstOrDefault().Score < 0.75)
{
await context.Forward(new FirstDialog(), AfterForward, context.Activity.AsMessageActivity(), CancellationToken.None);
context.Wait(base.MessageReceivedAsync);
}
else
{
await base.DefaultWaitNextMessageAsync(context, message, results);
}
}
这篇关于已经调用ResumeAfter方法,而无需在下一个对话框中调用context.done的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!