Build a chat bot using Azure Bot

    Today we have a practical lesson in creating chat bots using Azure Bot Service and Microsoft QnA Maker. In just a couple of hours of practical study you will be able to master these technologies. Join now!
    Please pay attention.

    For better mastering of the course, it is worth taking about two hours to it. In the course you will find a lot of practice and work on the virtual machine. In addition, we ask you to set aside the time for setting up the infrastructure that will be required for the passage of this module (All passwords for entering the virtual machine can be found on the “Resources” tab).

    Azure Bot, along with QnA Maker, provides the development tools needed to create and publish intelligent bots that naturally interact with users through a range of services.

    In this module, you will learn how to perform the following tasks:

    • Create a bot of the Azure web application to host the bot.
    • Creating a knowledge base, filling it with data and connecting the bot to it.
    • Introducing bots into code and debugging created bots.
    • Publishing bots and using continuous integration to keep up to date.
    • Perform local debugging of bots using the Visual Studio Code and the Microsoft Bot Framework Emulator.


    In this tutorial, you will need access to a virtual machine. If you are not connected yet, log in and click Start Virtual Machine Mode . The password for your account will be on the “Resources” tab. When clicked, it will automatically fill.

    Create an Azure web app bot

    The first step in creating a bot is to provide a place to host a bot in Azure. The Azure Web Applications component of Azure App Services is ideal for hosting bot applications, and the Azure Bot service is designed to prepare them. In this lesson, you will use the Azure portal to create a bot of the Azure web application.

    1. Log into the Azure portal by opening in the virtual machine browser.

    2. Select + Create resource, then Artificial Intelligence and Machine Learning and Web Application Bot.

    3. In the Application Name field, enter a name, for example, qa-factbot. This name must be unique within Azure. Make sure that a green check mark appears next to the name.

    4. Under Subscription and Resource Group, select available resources.

    5. Select the correct location (usually you do not need to change the already selected option).

    6. Select price category S1.

    7. Then select Bot Template. Select SDK v3 as the version, Node.js as the SDK language, and Question and answer as the template type. Then at the bottom of the column, click Select.

    8. Click Application Service Plan or Location, click Create, and then create an application service plan named "qa-factbot-service-plan" or another similar one in the same region selected in the previous step. Once this is done, click Create at the bottom of the bot column of the web application to start the deployment.


    Deployment usually takes two minutes or less.

    9. After the deployment is complete, click Resource Groups in the ribbon on the left side of the Azure portal.

    10. Select the resource group previously created for this group to open the resource group where we deployed the Azure web application bot.

    There should be several resources created for your Azure web app bot. Several events occurred during the deployment of the Azure web app bot. A bot was created and registered, an Azure web application was created to host it, the bot was configured to work with Microsoft QnA Maker . The next step is to create a knowledge base with questions and answers using QnA Maker in order to endow the bot with “intelligence”.

    Creating Knowledge Base with Microsoft QnA Maker Service

    QnA Maker is part of the Azure Cognitive Services package , which includes services and APIs for creating intelligent applications based on artificial intelligence and machine learning. Instead of including the bot's response to all possible user questions and all the necessary answers, it can be connected to the knowledge base with questions and answers created in the QnA Maker service. A common usage scenario is to create a knowledge base based on the URL list of the question and answer page, which allows the bot to answer specialized questions like “How to find a Windows product key?” Or “Where can I download Visual Studio Code?”

    In this exercise, you will use QnA Maker to create a knowledge base with some set of questions, such as “Which NFL teams won the most super cups?” And “What is the largest city in the world?” Then you will deploy this knowledge base in the Azure web application to it is made available via the HTTPS endpoint.

    1. Open the QnA Maker portal by opening in the virtual machine browser and selecting Sign in to sign in using the same lab account that you used to sign in to the Azure portal.

    2. Select the hamburger menu and click Create Knowledge Base.

    3. Click Create QnA Service.

    4. On the Azure Portal tab that opens, enter a name in the Name field. This name must be unique within Azure. Make sure that a green check mark is displayed next to the name and next to the Application Name field in the column below.

    5. Select Use existing in the Resource Group section, and then select the resource group previously created for this exercise.

    6. Select a location from the drop-down list (usually you do not need to change the already selected option).

    7. Select F0 for the Price Control Category option.

    8. Select F for the Price Search Category option.

    9. Make sure the Application Name is unique in Azure.

    10. Select the location closest to you in the two drop-down lists, then click the Create button at the bottom of the column.

    11. Select Resource Groups in the ribbon on the left side of the portal and open the resource group previously created for this exercise. Wait until the “Deployment in progress” sign at the top of the column changes to the “Successful” row, which indicates the successful deployment of the QnA service and its associated resources. If the message disappears, you can select the bell icon in the menu bar to view the status. You can also click Refresh at the top of the column to update the deployment status.

    12. Return to the Create Knowledge Base section by opening in the virtual machine browser, and scroll down to Step 2 to connect to our QnA service.

    13. In the Microsoft Azure Directory ID section, select Microsoft Learn Placement.

    14. Select Microsoft Learn Placement from the Azure Subscription Name drop-down list.

    15. In the Azure QnA Services section, select the QnA service whose name you specified earlier. If there are no services listed, refresh the page.

    16. Then assign a name to the knowledge base, for example “Factbot Knowledge Base”.

    17. Questions and answers can be entered into the QnA Maker knowledge base manually or imported from a list of frequently asked questions (FAQ) posted on the Internet or stored in local files. The following formats are supported: tab-delimited text files, Microsoft Word documents, Excel spreadsheets, and PDF files.

    To demonstrate, open the virtual machine browser and download the file This zip folder contains a text file named Factbot.tsv. Extract and copy the file to your local computer. Scroll down to the QnA Maker portal page in the virtual machine browser, click + Add file, and select the Factbot.tsv file. This file contains 20 questions and answers in a tab-delimited text format.

    18. Click Create a knowledge base at the bottom of the page and wait for its creation to complete. The operation will take no more than a minute.

    19. Make sure that the questions and answers from the Factbot.tsv file appear in the knowledge base. Then click Save and train and wait for the training to complete.

    20. Click the Test button to the right of the Save and train button. Type “Hi” in the message box, and then press ENTER. Make sure you get the answer “Welcome to the QnA Factbot” (Welcome to the QnA Factbot bot), as shown below.

    21. Type the question “What book has sold the most copies?” In the message box and press ENTER. How did you get the answer?

    22. To close the test panel, click the Test button again.

    23. Now click Publish in the menu at the top of the page, and then click the Publish button at the bottom of the page to publish the knowledge base you created. The publication will make the knowledge base available as an HTTPS endpoint.

    Wait for the publishing process to complete, and verify that the QnA services are deployed. The knowledge base is now hosted in the Azure web app and you can deploy a bot that will use this database.

    The following parts of the guide are available on our updated Microsoft Learn resource: cont .

    Also popular now: