Deploy a FAQ Bot with QnA Maker, Azure Bot Service and Telegram
Tags: azure, tutorial, webdev
Published: 2020-03-21 22:53:18

Today, more and more mobile devices are integrating 'bots' to interact and anticipate the tastes of users.

The word bot is derived from the term robot and becomes the software version of it. Simply put, it's an application developed to perform a different number of tasks autonomously.

It's often easier to chat with a bot than to search/read through a wall of text. "Chat bots" for example, make use of natural language processing to join users' messages with appropriate responses.

In this tutorial we'll learn how to build a bot with QnA Maker service, Azure Bot service and the Telegram messaging service.

####Knowledge base####

According to Wikipedia, the knowledge base is a special type of database for knowledge management. Provides the means for the collection, organization and computerized retrieval of knowledge. In other words, it is the source of information that will allow us to establish answers to a response for a particular case study.
 
For our case, the objective of the bot will aim to answer questions about computer terms, among these, computer components, peripherals, operating system fundamentals, etc. 

The knowledge base will consist of a Microsoft Word document, a file like any other.

Knowledge base source: [KB.docx](https://1drv.ms/w/s!ApLRabRfUdwZg-50jkC0PLiv6naAkA?e=VziSQR)

Other knowledge bases may also consist of PDF files, Excel files, some information page with data about the domain to work, SQL or NoSQL databases, or any other means that may provide information to a bot of type Informative.

##Part 1: Qna Maker##

The first thing we need to do is establish our knowledge base. For this purpose we make use of Qna Maker, a service that is part of the Azure catalog, which has its own web portal to build and publish knowledge bases also shortly referred to as KB. 

QnA Maker automatically extracts question and answer pairs from semi-structured content, such as FAQs, product manuals, guidelines, support documents, and stored policies (from the Word document for this case).

The goal is to consume this knowledge base from the Bot service for the construction of the FAQ bot from Telegram. The flow between the knowledge base and bot service is as shown below:

![](https://dev-to-uploads.s3.amazonaws.com/i/chj6jhsg7qh5q2ws9hlx.jpg)

All right, to establish the knowledge base we need to go to the page: [www.qnamaker.ai](www.qnamaker.ai) and sign in with our Azure account.

![](https://dev-to-uploads.s3.amazonaws.com/i/dadkgd73vw02ab7g72iq.png)

Later we will go to the section: Create a knowledge base. In this section we will need to carry out two quick activities:

####1. Create a QnA service in Azure. ####

In this case, the QnA Maker page will show you the option that will allow you to go to the Azure portal to create the resource:

![](https://dev-to-uploads.s3.amazonaws.com/i/gqitq6qvxoghs5uwrvzg.png)

Once in Azure, we need to specify the name of the resource, the plan, its location, and the other fields required for the creation of the resource.

![](https://dev-to-uploads.s3.amazonaws.com/i/j68kadaicl477u0g0735.png)

####2. Connect the Azure QnA service to our knowledge base. ####

After you create the QnA service resource in Azure, the following section is to refresh the page to define the knowledge base:

![](https://dev-to-uploads.s3.amazonaws.com/i/k1v01a0s4j4ob9dl9rmo.png)

In the first instance we will need to select our Azure subscription along with the Qna Maker resource created earlier. Then we must select the language. The language to be selected will be according to the language of the knowledge base and then the language of interaction with the bot.

![](https://dev-to-uploads.s3.amazonaws.com/i/y7gsbgl9y3sy989d30hs.png)

Next, we will have to enter the name of the KB knowledge base and specify the data source, for our case it will be a Word file:

![](https://dev-to-uploads.s3.amazonaws.com/i/4xunffbxvcuvhv9ms6kp.png)

Finally, you'll have the option to specify the style or "personality" of the bot:

![](https://dev-to-uploads.s3.amazonaws.com/i/b4ru1ck3wwnpw3yxys8k.png)

Example. For the user's query: `When is your birthday?`, each personality has a stylish response:

+ Professional: Age does not go with me.
+ Descriptive: I really don't have an age.
+ Ingenious: I don't have an expiration.
+ Affectionate: I'm not old.
+ Enthusiast: I'm a bot, so I'm not old.

Finally we created the knowledge base. At the end of the process, we will be able to interact with the knowledge base or publish it to access it through a web service or directly from a bot:

![](https://dev-to-uploads.s3.amazonaws.com/i/o61l1kab8sneho3v7kwf.png)

When publishing:

![](https://dev-to-uploads.s3.amazonaws.com/i/vnc2krinhd9g3xn4ukcn.png)

In this case we will receive the help of the QnA Maker portal to create the bot. When you go to that section: Create Bot, we'll be redirected to the Azure portal to create a new Bot Service resource, most of the required fields will already be automatically filled with the necessary information:

![](https://dev-to-uploads.s3.amazonaws.com/i/cilfk024s5xq267jdcpi.png)

All right, with these steps we already have the knowledge base in Qna Maker ready just like the Bot Service.

##Part 2: Bot service + Telegram##

In this second step our goal is to connect the previously created bot with some messaging service, in this case: Telegram. The sequence to be performed is as follows:

![](https://dev-to-uploads.s3.amazonaws.com/i/66axe6yerbjmosmh41u3.png)

However, in the Web App Bot resource, we go to the Channels section to configure the settings between the messaging service and the bot. 

The messaging channels we have available to connect to your bot are as follows:

+ Bing
+ Cortana
+ Email
+ Facebook
+ GroupMe
+ Microsoft Teams
+ Skype / Skype for Business
+ Telegram
+ Twilio
+ Web Chat

Each messaging channel has some variation when performing the respective configuration. As mentioned above, our messaging system to use will be Telegram.

![](https://dev-to-uploads.s3.amazonaws.com/i/0s7z24b61ex6ao4vdrux.png)

When accessing this messaging channel, the Azure portal will request a Token, which will allow you to establish the connection between a telegram bot and the bot created in Azure.

![](https://dev-to-uploads.s3.amazonaws.com/i/z9e8dwe276956vjbq33g.png)

To create a bot on Telegram we must visit BotFather to fulfill this goal. Once there we must type the command: /newbot. 

BotFather will ask you to specify the bot name and a unique username for your bot. When finished, we will have a message stating that the bot has been created and access to the respective token.

![](https://dev-to-uploads.s3.amazonaws.com/i/1kskcx88f41d4mxxii4l.png)

##The bot on Telegram is ready...##

With these steps, we're ready to interact with our Q&amp;A bot. Here is an example:

![](https://dev-to-uploads.s3.amazonaws.com/i/zuk4258q1ma234ln8650.png)

##Conclusions##

Bots represent a real revolution in the way we transact on the Internet and our daily tasks. According to Microsoft CEO Satya Nadella, "bots will be the apps of the future and spoken language will be the new way to interact."

In the relatively near future, the trend is in the generation of bots with increasing processing capacity thanks to the implementation of new concepts and services in the field of Artificial Intelligence. In the case of chatbots, their use continues to grow exponentially, which has allowed them to generalize messaging applications that will make these bots a common form of interaction between consumers and companies.

##Thank you.##

See you on [Twitter](https://twitter.com/esDanielGomez)!! :)