Connecting Your Azure Bots with QnA Maker Services

Connecting Your Azure Bots with QnA Maker Services

Connecting Your Azure Bots with QnA Maker Services is the first step you need perform to connect you Bot with QnA Maker. Azure Bot Service is the Bot-Service powered by the Microsoft Bot Framework and Microsoft Azure. It enables rapid intelligent bot development. Azure Bot Service provides an end-to-end integrated environment for setting up backend services bot development. You can develop a bot, deploy it, connect it to different channels, test it in inbuilt web chat emulator, and modify the code from your web browser itself. Azure QnA Maker helps you in Build, train and publish a simple question and answer bot based on FAQ URLs, structured documents or editorial content very quickly and easily.


When you create a Bot using Azure Bot Service using “QnA Maker” template the Bot wont work unless you link the Bot Service with QnA Maker Service. In case you start testing the default created bot, the bot will send back following response.

Get QnA Maker Keys

From the given message it is clear that you need to provide the QnAKnowledgebaseId and QnASubscriptionKey in App Settings.

First get the Publish API settings from QnA Maker, you will find them from the Sample HTTP Request.

 

Getting the API Key for QnA Maker

Go back to the Web App Bot and navigate to the Application Settings available under App Service Settings. There you will find two app settings entry for QnAKnowledgebaseId and QnASubscriptionKey. Update the settings values and save it.

Applying ID for QnA Maker

Post that if you go back and test the Bot, you will able to get the bot responses based on the QnA Makers Questions and Answer.

 

If you want to Integrate through application code, you need to update the keys in the Web.Config file. Enter the same values for QnAKnowledgebaseId and QnASubscriptionKey in appSettings

Web Config Entry

Once Web.config is updated you can use following set of code to read the config file and send a call back to QnAMaker Services.

 var qnaSubscriptionKey = WebConfigurationManager.AppSettings["QnASubscriptionKey"];
            var qnaKBId = WebConfigurationManager.AppSettings["QnAKnowledgebaseId"];


            if (!string.IsNullOrEmpty(qnaSubscriptionKey) && !string.IsNullOrEmpty(qnaKBId))
            {
                await context.Forward(new BasicQnAMakerDialog(), AfterAnswerAsync, message, CancellationToken.None);
            }
            else
            {
                await context.PostAsync("Please set QnAKnowledgebaseId and QnASubscriptionKey in App Settings. Get them at https://qnamaker.ai.");
            }

Hope this helps.

Geek's Choice

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

One Comment to “Connecting Your Azure Bots with QnA Maker Services”

Comments are closed.