In this post, we will talk about the Azure Bot and QnA Maker service. To create an Azure Bot we must use the Bot Framework, with this framework developers are able to build intelligent bots to interact with users in  multiple ways, like text, Skype, Slack, O365 etc.

Azure Bot Connectors

Τhe Bot connectors are similar to logic apps connectors, and allow users to exchange messages. There are many channels that the bot service can send messages, for example, Facebook, Skype, Slack, MS Teams, Cortana, Twilio, Skype for Business etc.

Azure Bot Service

This is a service that gives the ability to deploy chat bots which interact with humans.  The Azure Bot service uses Microsoft Bot Framework for the deployments. We can use different program languages like C#, Node.js.

Create a Bot Service

In the following steps, we will create an Azure Bot using the Azure Portal.

Search For Web App Bot

First, search for {Bot} service like the image below  and Select [Web App Bot].

Click Create to begin Web App Bot Service deployment.

Web App Bot (Bot Service)

Fill in all the fields in the Web App Bot deployment blade and click the Create button.

Bot nameType the Bot name
SubscriptionSelect a valid Azure Subscription
Resource groupSelect an existing or create a new Resource Group
LocationSelect a location for the Resource Group
Pricing tierSelect a pricing tier, more details in this link.
App nameType a unique name for the Azure bot
Bot templateChoose a bot template,actually we have two options between C# or Node.js
Hosting PlanSelect the hosting plan for the service
Azure StorageSelect an existing or create a new storage account for the table storage that the bot needs.
Application InsightsSet On or Off the Application Insights service
Application Insights LocationIf the previous setting is On the we must select a location, that the logs stored
Microsoft App ID and passwordCreate manually or automatically Microsoft App ID and password  for the bot service

Bot templates

At the following table, we can see  the templates for Azure bot service,on both C# and Node.js program languages.

The SDK version for the templates is v3. SDK v4 is not yet available for the Question and Answer bot.

C#, Node.js Language

On the following table we can see the Bot templates and the details for each.

BasicA bot with a single dialog that echoes back the user input
FormA bot that shows how to collect input from a user using a guided conversation using FormFlow
Language understandingA bot that shows how to handle natural language using the Cognitive Services LUIS API
Question and AnswerA bot that distills information into conversational, easy-to-navigate answers
ProactiveA bot that shows how to use Azure Functions to trigger events in Azure bots

QnA Maker

QnA Maker is an API service which allows users to create Knowledge base using questions and answers. This goal can be achieved using different sources.
In the following steps we create an Azure Service for the QnA knowledge base.

Create a QnA service in MS Azure

Select Create a QnA service, to create the KB that the Web App Bot use.  []

Next we need to fill in all the necessary values, and select Create.

NameType the QnA name
SubscriptionSelect a valid Azure Subscription
Management pricing tierSelect a pricing tier for the QnA cognitive service. Check for more details in this link
LocationSelect the QnA service location
Resource groupSelect a location for the Resource Group
Searching pricing tierSelect a Search pricing tier, view full pricing details in this link
Search locationSelect the Search service location
App nameType a Name the app service
Website locationSelect  location for the Website
App insightsSet Enable or Disable the Application Insights service
App insights locationIf the previous setting is Enable,the we must select a location, that the logs stored

Connect QnA service to KB

At the second step select the Azure service options as the image below shows.

Microsoft  Azure Directory IDSelect an Azure Directory
Azure subscription nameSelect the subscription
Azure QnA serviceSelect the Azure QnA Service, which deployed in the step 1

Name the KB

Type a name for the Knowledge Base KB

Populate the KB

The fourth step is to populate the KB. There are several ways to populate a KB like URL and file.

Data Sources for QnA Maker Content

At the table below we can find the source and content type that QnA Maker support.

Source TypeContent Type
URLFAQs (Flat, with sections or with a topics homepage)
PDF / DOCFAQs, Product Manual, Brochures, Paper, Flyer Policy, Support guide, Structured QnA, etc.
ExcelStructured QnA file (including RTF, HTML support)
TXT / TSVStructured QnA file

Create the KB

At last step we only need to select the [Create your KB] button.

Knowledge Base

After the KB is created we can see the pair of questions and answers, from the link we provided to the KB.

The next step is to select [Save and train] and when it finishes, click [–> Test] to test

Now, we must publish the KB to the QnA Maker service. This can be done by selecting PUBLISH menu, and click the button [Publish].

Configure Web App Bot To Use the KB

Configure the App Settings

From the Web App Bot main blade, select Bot management Application Settings

The settings for the Web App Bot, are available from the QnA Maker portal {}. At the image below we can see the sample from this post demo.
We need the first three parameters which are QnAKnowledgebaseid, QnAEndpointHostName, and QnAAuthKey.

These parameters must be added at the Web App Bot Application Settings. 

From the main Web App Bot main blade, App Service Settings > Application Settings.

QnAAuthKeyEndpointKey 12345678-ee18-548d-8402-9457615e9447

Connect The Azure Bot To Skype

From the Web App Bot main blade, Bot management Channels, select Skype

Select the Publish menu, and click Save.

A new pop-up message comes up about Term of Service, mark the checkbox that you Agree on that and select the button Agree.

After previous steps when we open the Channels menu we able to select the Skype channel,

Add the cloudwebappbot to Skype contacts. And now we are in position to ask the bot and it will answer to us.

The next image shows the question from a human and the answer from the bot.

Build Azure Web App Bot on Visual Studio IDE

Previously we saw how we can deploy an Azure Web App Bot with the ‘easy’ way in this point we will see the steps for the ‘hard’ way?
No! It is not as difficult as it looks in the first look. We just need to follow a couple of steps and if we are familiar with programming then Bot Framework development should be a piece of cake.

Download The Code

From the Overview, blade and select the Build: image.

Next step is to click Download Bot source code, as the image below shows.

Web Config configuration

The following code show how to setup the web app configuration file.
We need to add the following <add key> tags :

  • <add key=”AzureWebJobsStorage” value=””/>
  • <add key=”QnAAuthKey” value=””/>
  • <add key=”QnAEndpointHostName” value=””/>
  • <add key=”QnAKnowledgebaseId” value=””/>
    <!-- For more information on Entity Framework configuration, visit
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- update these with your Microsoft App Id and your Microsoft App Password-->
    <add key="MicrosoftAppId" value="123456789-1234-5678-1122-aabbccddeefff" />
    <add key="MicrosoftAppPassword" value="XXXXXXXXXXX" />
    <add key="AzureWebJobsStorage" value="DefaultEndpointsProtocol=https;AccountName=accountname;AccountKey=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==;"/>
    <add key="QnAAuthKey" value="EndpointKey xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>
    <add key="QnAEndpointHostName" value=""/>
    <add key="QnAKnowledgebaseId" value="254845242-8790-3423-1122-aabbccddeefff"/>

The Bot Framework-Emulator

Download Emulator from GitHub

We can download the Bot Framework emulator from Github.

Configure the Bot Framework-Emulator

After setup is finished, the emulator opens and need to make some configurations to start working.
From File menu, select New Bot Configuration..

In the configuration form fill in the required parameters.

Bot name*Type an Azure Bot Name
Endpoint URL*Copy the URL from the Visual Studio and pasted by adding /api/mesages
Microsoft App ID`Copy and paste the Microsoft App ID from the VS app settings
Microsoft App passwordCopy and paste the Microsoft App password from the VS app settings

After we type all the necessary values in the Net bot configuration form, we click the button Save and connect

Deep Dive In The Code

In this example we download the bot framework code from Azure. To test this code with the emulator we need to make few changes in the code.

BasicQnAMakerDialog.cs file

Make all the necessary changes in the C# code as the following code blocks show.

private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
    /* When MessageReceivedAsync is called, it's passed an IAwaitable<IMessageActivity>. To get the message,
     *  await the result. */
    var message = await result;
    // Add Comment from the line 29 - 31
    /*  var qnaAuthKey = GetSetting("QnAAuthKey");
      var qnaKBId = Utils.GetAppSetting("QnAKnowledgebaseId");
      var endpointHostName = Utils.GetAppSetting("QnAEndpointHostName");*/
    // Add the code from the line 35 - 37
    var qnaAuthKey = ConfigurationManager.AppSettings["QnAAuthKey"];
    var qnaKBId = ConfigurationManager.AppSettings["QnAKnowledgebaseId"];
    var endpointHostName = ConfigurationManager.AppSettings["QnAEndpointHostName"];
    // QnA Subscription Key and KnowledgeBase Id null verification
    if (!string.IsNullOrEmpty(qnaAuthKey) && !string.IsNullOrEmpty(qnaKBId))
        // Forward to the appropriate Dialog based on whether the endpoint hostname is present
        if (string.IsNullOrEmpty(endpointHostName))
            await context.Forward(new BasicQnAMakerPreviewDialog(), AfterAnswerAsync, message, CancellationToken.None);
            await context.Forward(new BasicQnAMakerDialog(), AfterAnswerAsync, message, CancellationToken.None);
        await context.PostAsync("Please set QnAKnowledgebaseId, QnAAuthKey and QnAEndpointHostName
(if applicable) in App Settings. Learn how to get them at");

Make changes in the Dialog for QnAMaker Preview service

// Dialog for QnAMaker Preview service
 public class
BasicQnAMakerPreviewDialog : QnAMakerDialog
     static readonly
qnaAuthKey = ConfigurationManager.AppSettings["QnAAuthKey"];
     static readonly
qnaKBId = ConfigurationManager.AppSettings["QnAKnowledgebaseId"];
     static readonly
endpointHostName = ConfigurationManager.AppSettings["QnAEndpointHostName"];
     // Go to and feed data, train & publish your QnA Knowledgebase.
     // Parameters to QnAMakerService are:
     // Required: subscriptionKey, knowledgebaseId,
     // Optional: defaultMessage, scoreThreshold[Range 0.0 – 1.0]
     public BasicQnAMakerPreviewDialog() : base(new QnAMakerService(new QnAMakerAttribute(qnaAuthKey, qnaKBId, "No good match in FAQ.", 0.5, endpointHostName: endpointHostName)))
     { }

Final changes must be made in the Dialog for QnAMaker GA service

// Dialog for QnAMaker GA service
    public class
BasicQnAMakerDialog : QnAMakerDialog
        static readonly
qnaAuthKey = ConfigurationManager.AppSettings["QnAAuthKey"];
        static readonly
qnaKBId = ConfigurationManager.AppSettings["QnAKnowledgebaseId"];
        static readonly
endpointHostName = ConfigurationManager.AppSettings["QnAEndpointHostName"];
        public BasicQnAMakerDialog() : base(new QnAMakerService(
            new QnAMakerAttribute
                "No good match in FAQ.",

Test the Web App Bot  via the Bot Framework Emulator,


In this wiki post we read how someone who wants to use the Azure Bot Service for the first time. can easily deploy an Azure Bot with QnA Maker service  via the Azure Portal and how a dev can download the code locally and test the changes using the Azure Bot Framework Emulator.

See Also

Share This