Building bots with the Microsoft Bot Framework is fun, but a complex dialog structure can get out of hand quickly. While juggling different types of nested dialogs with follow-up questions and adaptive cards I wanted to be able to answer simple questions at any step of the conversation. Queries like “what can I say”, “contact information” or “I need help” are usually handled by Global message handlers using scorables.
For handling static content I really like Microsofts QnA Maker service, which allows you to specify simple question-answer-pairs which is great for most static content since its easy to maintain without editing, building and redeploying the code. The interface is also very easy to understand so non-coders can add or update content while the bot is live.
So adding the QnA Maker Service as a Scorable seemed like a good idea, and it’s actually very easy. Too bad the documentation is incomplete, but digging through the samples I found it’s as easy as registering the ready-to-use QnAMakerModule from the Microsoft.Bot.Builder.CognitiveServices NuGet Package in your Global.asax.cs Application_Start()-method.
builder.RegisterModule( new QnAMakerModule( "set yout subscription key here", "set your kbid here", "I don't understand this right now! Try another query!", 0.50 ) );
All you need is your QnA Maker subscription key, knowledgebase id, a default response message and a double value indicating when this scorable should take over and respond to the user.