Building a FAQ Bot with the QnA Maker Cognitive Service

The QnA Maker cognitive service has fast become the backbone for many customer service bot scenarios.  Once you have created your QnA service and published it, it's time to incorporate it into your bot framework bot.  To date, there are a couple of ways to implement it from C#.

# Option 1 - use the Microsoft.Bot.Builder.CognitiveServices nuget package

You'll then need to create a class that uses the QnAMakerDialog eg:

 public class FAQDialog : QnAMakerDialog
 public FAQDialog() : base(new QnAMakerService
 (new QnAMakerAttribute(ConfigurationManager.AppSettings["QnASubscriptionKey"], 
 "Sorry I don't understand, please rephrase your question.", 
 { }


Then ensure you've set the following keys within your web.config:

<add key="QnASubscriptionKey" value="QnASubscriptionKey" /> 
<add key="QnAKnowledgebaseId" value="QnAKnowledgebaseId" />

Full sample here:

# Option 2 - use the QnAMakerDialog nuget package by Gary Pretty (MVP)

This has a couple of nice features, such as being able to attribute methods with the QnA confidence score and being able to add attachments to responses.  More of which can be discovered here:

[QnAMakerService("QnASubscriptionKey", "QnAKnowledgebaseId")] 
public class FAQDialogGP: QnAMakerDialog<object> 
public override async Task NoMatchHandler(IDialogContext context, string originalQueryText) 
await context.PostAsync($"Sorry, I couldn't find an answer for '{originalQueryText}'."); 

Full sample here:

Comments (2)

  1. Rick says:

    I click on “Download Chat Logs” and nothing happens. What could be the problem.
    Thanks in advance

    1. Jamie Dalton says:

      Hi Rick,

      Check if your pop-up blocker is preventing you from downloading the csv files within the portal.



Skip to main content