Partilhar via


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

https://www.nuget.org/packages/Microsoft.Bot.Builder.CognitiveServices

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

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

 }

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: https://github.com/Microsoft/BotBuilder-CognitiveServices/tree/master/CSharp/Samples/QnAMaker

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

https://www.nuget.org/packages/QnAMakerDialog/

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:

 [Serializable] 
[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}'."); 
context.Wait(MessageReceived); 
} 
}

Full sample here: https://github.com/garypretty/botframework/tree/master/QnAMakerDialog/QnAMakerDialog.Sample

Comments

  • Anonymous
    May 25, 2017
    HiI click on "Download Chat Logs" and nothing happens. What could be the problem.Thanks in advanceRick
    • Anonymous
      May 31, 2017
      Hi Rick,Check if your pop-up blocker is preventing you from downloading the csv files within the QnAMaker.ai portal.Thanks,Jamie