0

I am trying to closing a QnAMaker dialog so that user can go back to the Luis dialog and use it again.

here is my code that i use in luisdialog.cs:

    [LuisIntent("FAQ")]
    public async Task FAQ(IDialogContext context, LuisResult result)
    {
        await context.PostAsync("FAQ");
        var userQuestion = (context.Activity as Activity).Text;
        await context.Forward(new QnADialog(), ResumeAfterQnA, context.Activity, CancellationToken.None);

        //await Task.Run(() => context.Call(new QnADialog(), Callback));
    }
    private async Task ResumeAfterQnA(IDialogContext context, IAwaitable<object> result)
    {
        context.Done<object>(null);
    }

While here is the QnA dialog:

[Serializable]
[QnAMakerService("endpoint", "knowledge base id", "subscription key")]
public class QnADialog : QnAMakerDialog<object>
{

}

I tried to override the start async method so that it will quit the dialog by using context.done(0) if the user type "done" but the QnA maker doesn't start at all which is confusing.

Also why is that by calling the luis intent using "FAQ" it also tried to go to the knowledge base without the user typing it again is it possible to fix that ?

user3646742
  • 199
  • 12

1 Answers1

1

I am trying to closing a QnAMaker dialog so that user can go back to the Luis dialog and use it again.

You can try to override the DefaultMatchHandler and call context.Done to close QnAMaker dialog and pass control back to the parent dialog. The following modified code snippet work for me, please refer to it.

In LuisDialog:

[LuisIntent("FAQ")]
public async Task HelpIntent(IDialogContext context, LuisResult result)
{
    await context.PostAsync("FAQ");
    await context.Forward(new QnADialog(), ResumeAfterQnA, context.Activity, CancellationToken.None);
}

private async Task ResumeAfterQnA(IDialogContext context, IAwaitable<object> result)
{
    //context.Done<object>(null);
    context.Wait(MessageReceived);
}

In QnADialog:

public override async Task DefaultMatchHandler(IDialogContext context, string originalQueryText, QnAMakerResult result)
{
    await context.PostAsync($"I found {result.Answers.Length} answer(s) that might help...{result.Answers.First().Answer}.");
    context.Done(true);
}

Test result:

enter image description here

Fei Han
  • 26,415
  • 1
  • 30
  • 41
  • do u have sample or a document for above code which i can follow ? – Ronak Shetiya Jul 27 '18 at 09:36
  • You can refer to [this github samples](https://github.com/Microsoft/BotBuilder-CognitiveServices) to get started with the QnA Maker dialog and Luis dialog. – Fei Han Jul 31 '18 at 05:51
  • thanks that work, but just want to ask is it possible to get into the FAQ intent then based on the user question it start going to knowledge bases? not right away ? so something like below: FAQ Welcome to FAQ intent please start asking question what is the rate limit rate limit are 100, are there any more question? no thanks. afterward it goes back to the luis intent. I can get out from the FAQ intent by checking if the user typing "no", by checking if originalQueryText=="no", context.Done(true) but not too sure how to proceed from there. – user3646742 Aug 02 '18 at 20:34