Thursday, 15 March 2018

Bot Framework Tutorial 4: Creating a Question and Answer(Qna) Bot

In the Tutorial 2, we learnt how to create a basic bot in Azure. In this lesson, we would take it a step further and learn how to create a question and answer bot.


  1. What is a Question and Answer Bot
  2. Understanding LUIS
  3. The QnaMaker
  4. Steps Build a QnA Bot
  5. Final Notes and Next Step

1. What is a Question and Answer Bot?

This a bot that makes use of a question and answer databases to provide interactions with users by provided responses to user questions.

A question and answer bot allows you to discuss with it and while you ask questions, it provides you with relevant answers based on the content of the knowledgebase.

2. Understanding LUIS

LUIS stands for Lanuguage Understanding Intelligent Service offers a fast and effect way of adding language understanding to applications. Using LUIS, you can use pre-existing models to create Bots that can interact with users in a more natural way.

LUIS allows your application to understand what someone wants in their own words. It makes use of machine learning algorithms to allows developers to build applications taht can recieve input from user in a natural language and then deduce the intended meaning.

Learn more about LUIS from What is LUIS (Language Understanding Intelligent Service)

3. Understanding The QnaMaker

One of the key features of a Bot is to be able to seed it with a list of questions and answers. This list could be in a spreadsheet, document file, pdf, web page etc.

The QnaMaker is a free and easy to use REST API  that trains AI to respond to users' question in a more human and conversational way.

With QnA Maker you can have a list of predefined questions and answers you have created. Then you can load this data to the service to create a knowledgebase and then trains it to respond to cetain variations of the question in the knowledgebase.

In this tutorial, we would create a Qna Service in QnaMaker and then use this service in the Question and Answer bot we would be creating.

You can read more about QnaMaker from the Qna Documentation

Figure 1 Illustrate how QnaMaker integrates with Bot Framework.

Figure 1: Photo taken from

4. Steps to Create a QnA Bot

Take the following easy steps to complete the process of creating a Qna Bot

Step 1: Create the QnA KnowledgeBase

You will create a list of questions and answers that would be used by the bot.You will do this in Microsoft Word or any other text editor you have. Create the question and answers using the format shown in Figure 1.

Save the file with a name. We will upload this file to QnaMaker

Step 2: Create a new QnA Service

Go to
Login using your Microsoft Account

Click on Create new Service.
The new qnaService creation form opens as shown in the Figure.

Enter a name you would like to give to the service
Leave the URL field bland

Scroll down to the Upload File section.
Click Select File and select the file you created in step 1.

After the file have uploaded, click on Create
The window below is displayed. It takes a few seconds to process the request.

When the processing is completed, the next page is displayed

To test the Service, Click on Test on the left side of the page.
Enter 'Hi' to see the response
Enter a question  and see if it responds with the correct answer
After testing, you then click on Publish to publish the qna Service

Click on Publish again the complete the deployment process

Then note donw the KnowledgeBase Id  and the Subcription Key as highlighted in the figure

You have successfully created a qna Service ready to be used in your bot in Microsoft Azure. You can go ahead to close the Window and login to Microsoft Azure

Step 3: Create a Question and Answer Bot in Azure

Follow the bot create process to create a Question and Answer bot in Azure.
See how to create a bot here

Important: In the Bot Template, you must Choos Question and Answer

Step 4: Link the QnA Bot to the Qna Service

Go to the Application Setting. This is under App Service Setting
Scroll down to find QnaKnowledgeBaseID and QnaSubscription Key

Now you need to enter the KnowledgebaseID and Subscription key you got from Step 2

When you are done, click on the Save button at the upper part of the window.
Now, you are ready to roll!

So let's now test our Question and Answer Bot

Step 5: Test thet Bot

Under Bot Managment, Click on Test in Web Chat
Enter one of the questions defined in the Question and Answer file we created
Try some other question
Try entering a question that is not there.😃😄

5. Final Notes

If you have completed this lessons successfully, thumbs up to you! If you have challenges along the line, you can let me know at the form by the left of this page that says, 'Your Opinion Matters'.
I would also like to tell you  that if you did this successfull, then almost every other aspect of bot framework would not be a bid deal for you.
Let't now move on to the next steps,  where we would learn how to configure channels for out bot.