0
votes

Need to call the QnA bot from the Main Dialog whenever the intent is None, Can we do that or it can be done via dispatcher?

In MainDialog : I have added like: AddDialog(new QnABot(userState)); --- Like this I called other dialogs.

And called in None intent like: await stepContext.BeginDialogAsync(nameof(QnABot), cancellationToken);

Can we call QnA bot from MainDialog or using Dispatcher is better option?

1

1 Answers

0
votes

The purpose of dispatch is to handle routing to multiple LUIS or QnA models. For example, if you have 2 QnA models (one for chitchat like "How are you?" and "Are you human?" and one for actual faq questions like "How do I make an appointment"), and 1 LUIS model, you would umbrella all of this with a dispatch. Deep down, a dispatch is just a fancy LUIS model. It returns a simple model name instead of an actual reply, and you use the reply to call QnA.

For your example, I would use dispatch, yes. picture of dispatch model

Anything that ends up under that 'None' intent is going to return 'none' in my bot logic. Here's how to get the intent from Dispatch:

// Check dispatch result
var dispatchResult = await cognitiveModels.DispatchService.RecognizeAsync<DispatchLuis>(dc.Context, CancellationToken.None);
var intent = dispatchResult.TopIntent().intent;

And here's how I would use it to call QnA (using the 'None' intent):

else if (intent == DispatchLuis.Intent.None)
{
    cognitiveModels.QnAServices.TryGetValue("faq", out var qnaService);
    if (qnaService == null)
    {
        throw new Exception("The specified QnA Maker Service could not be found in your Bot Services configuration.");
    }
    else
    {
        var answers = await qnaService.GetAnswersAsync(dc.Context, null, null);                   
        if (answers != null && answers.Count() > 0)
        {
            await dc.Context.SendActivityAsync(answers[0].Answer, speak: answers[0].Answer);
        }
        else
        {
            await _responder.ReplyWith(dc.Context, MainResponses.ResponseIds.Confused);
        }
    }
}

These examples are all pulled from the Botframework-Solution's Virtual Assistant Bot. I would also take a look at this doc for how language understanding works.

As an aside, I would recommend against naming your dialogs "--bot", because in the long run, you're going to confuse yourself.