0

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.

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:

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);

    }
}

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) {
    }
}

2nd Luis Dialog:

[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);
}

CallBackHandler Method in First Luis Dialog is called right after Forward is executed.

Waqas Zia
  • 56
  • 4

1 Answers1

0

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

Try overriding the DefaultWaitNextMessageAsync method instead:

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);
    }
}
Nicolas R
  • 13,812
  • 2
  • 28
  • 57
Eric Dahlvang
  • 8,252
  • 4
  • 29
  • 50