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.
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
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.
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:
All right, to establish the knowledge base we need to go to the page: www.qnamaker.ai and sign in with our Azure account.
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:
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.
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:
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.
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:
Finally, you’ll have the option to specify the style or “personality” of the bot:
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:
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:
All right, with these steps we already have the knowledge base in Qna Maker ready just like the Bot Service.
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:
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:
- Microsoft Teams
- Skype / Skype for Business
- Web Chat
Each messaging channel has some variation when performing the respective configuration. As mentioned above, our messaging system to use will be Telegram.
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.
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.
With these steps, we’re ready to interact with our Q&A bot. Here is an example:
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.