Search code examples
c#botframeworkazure-cognitive-servicesazure-qna-maker

How to call QnA Maker on a waterfall dialog using C#?


I am trying to call QnA Maker on a waterfall dialog step.

How do I call it from this watterfall step, do I need to set up QnA On the waterfall step, do I need to call QnA from a LUIS intent, what can I do?

Code

I need it to get the first result from the QnA using the step context from the previous question.

Can anyone help?

Code:

private async Task<DialogTurnResult> QnaAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
    var response = await qnaMaker.GetAnswersAsync(stepContext);

    // use answer found in qnaResults[0].answer
    return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text(response[0].Answer)}, cancellationToken);
}

Solution

  • It looks like you don't have qnaMaker defined in your code above, there. You can really call QnAMaker from anywhere, so long as you have a QnAMaker service defined somewhere.

    I recommend following this sample. It's fairly complex, but is the best example of using QnAMaker within a Waterfall Dialog.

    I'll point out some pieces that you will find most useful:

    1. Create the QnAMaker service
    2. Use dependency injection so that you can access the BotServices from anywhere in the project
    3. Add the services to the dialog's constructor
    4. Call the QnAMaker service

    Again, that sample is fairly complex. If you need additional pointers, please update your question with the code that you've tried and I'll see if I can help.