How to: Use QnA Maker with Azure Function Bots

Posted Friday, March 9, 2018 10:55 AM by CoreyRoth

I have been working with bots a bit lately and wanted to share some of my experiences.  QnA Maker makes it really easy to built a bot to serve up a knowledge base based on simple question and answer pairs that you populate it with.  After you publish your knowledgebase with QnA Maker, it's a bit tricky to figure out what to do next.  When you click Publish, you get a screen like this.

Screen Shot 2018-03-09 at 10.19.30 AM

While this is useful information if you were going to interact with your bot directly via REST.  It doesn't tell you how to turn this into a bot.  In fact if you look for information on how to do this with an Azure Functions Bot, you'll find very little on it.  That's because all of the documentation and examples out there tell you how to do it with Bot Framework / Bot Service which is deprecated in lieu of the new Azure Functions Bot or Web App Bot. That's why I created this post to walk you through it.

Start by creating a new Functions Bot or Web App Bot.  The difference really just depends on how you want to pay for your consumption.  If you are just experimenting, I would probably go with a Functions Bot.  You can find both under AI + Cognitive Services.

Screen Shot 2018-03-09 at 10.37.34 AM

You'll need to give your bot a unique name.  You'll select the typical things like the Location, Azure Storage account, and Resource Group.  The key things you want to set are the Pricing tier and the Bot template.  For Pricing tier use F0 which includes 10K Premium Messages

Screen Shot 2018-03-09 at 10.40.47 AM

For the Bot template, click on it choose either C# or Node.js and be sure and choose Question and Answer.

Screen Shot 2018-03-09 at 10.40.13 AM

You also want to set your Hosting Plan.  I am going with Consumption Plan but this is really up to you.

Once your bot is provisioned, we now need to adjust a few settings.  This part used to be clearer with the old Bot Service stuff.  Click on Application Settings.

Screen Shot 2018-03-09 at 10.46.35 AM

Now we need a few values from QnA Maker.  Remember the publish screen?  It has the values we need.  We need the values for QnAKnowledgebaseId and QnASubscriptionKey.

Screen Shot 2018-03-09 at 10.19.30 AM

You can find QnAKnowledgebaseId in the GUID of the first line of the POST statement.  So in this case, mine is 73d71520-4c66-45ee-8fbf-acfeef3d1b05.

You can find QnASubscriptionKey in the third line Ocp-Apim-Subscription-Key.  In this case, mine is 9343c969f7ab4ac28b559c87ae6eb3d0.

Now we need to set these values in our Application Settings at the very bottom of the list.

Screen Shot 2018-03-09 at 10.53.32 AM

That's all you need to do.  Once you have configured those settings, your QnA bot is ready to go.  Try it out for yourself!

Filed under: ,

Comments

No Comments

Leave a Comment

(required)
(required)
(optional)
(required)