How to create a bot for FAQ in 4 steps

Messengers show constant growth of active users. WhatsApp has 1.5 billion active users every month. Facebook – 1.3 billion. Skype – 300 million. Messaging apps are getting bigger and they have surpassed social apps long time ago. Also the increase in time spent on messaging apps is massive. As a result, bot is a very attractive form of communication for end users. They naturally interact on a website, app or your favorite messaging application. In this article I will show how you can create a bot which understands the syntax of your sentence and gives you the reply from the database or from the Internet. With a bit of setup you can easily convert your static FAQ page into a bot which will answer your questions.

Bot Architecture

The number of bot platforms is now very large. For me, as Microsoft specialist, the clear choice is Microsoft Bot Framework. I am also going to use a bit of Artificial Intelligence using Microsoft Cognitive Services:

  • LUIS – A machine learning-based service to build natural language into apps, bots, and IoT devices.
  • QnA Maker – a question and answer service.
  • Bing Web Search – a search service to retrieve the results from the Internet.

This frameworks allow you to easily create a bot in a very short time.

In short, user types a phrase in a chat window. Next, the phrase goes to LUIS which tries to figure out whether it is a greeting or an actual question. If it is a question, LUIS tries to understand the intent and replies with the keyword. Then, the QnA Maker gets the keywords and tries to match it with the answer. If no answer found, then the keyword is routed to Bing Web Search and the public results are returned. Finally, the bot replies to the user – either with the response from the QnA Maker or with the Bing Search results.

How to create a bot

Now, let me go through all the necessary configuration.

1. Configuring LUIS

In LUIS I am going to configure the following elements:

  • Intents – An intent represents actions the user wants to perform. In our case we are going to have two intents: Greeting and Search.
  • Utterances – An utterance is text input from the user that your app needs to understand. It may be a sentence, like “What is Digital Experience”, “Tell me more about Digital Experience”, “I want to know more about Digital Experience”, etc.
    Entities – An entity represents detailed information that is relevant in the utterance. For example, in the utterance “What is Digital Experience”, “Digital Experience” is a keyword. By recognizing and labeling the entities that are mentioned in the user’s utterance, LUIS helps you choose the specific action to take to answer a user’s request.

Here are my LUIS intents:

In the greeting configuration I added the following utterances: “hi hello yo greetings hey”. This will allow LUIS to recognize the following words as a greeting and as a result it will reply appropriately.

For search I considered the following utterances:

  • what is Keyword
  • i want to know more about Keyword
  • tell me more Keyword
  • who is Keyword
  • i want to learn more about Keyword
  • tell me more Keyword

Here the Keyword is my simple Entity. I am sure you can think of dozens of different phrases for asking bot a question but a beauty of LUIS is that you can easily train it so it can get better and better.

2. Configuring QnA Maker

The QnA Maker configuration is pretty straightforward. It can be easily populated by adding a link to the FAQ page or uploading a Word or PDF document with question and answers.

For the purpose of the demo I only added 3 items to QnA Maker service:

QnA Maker configuration

3. Configuring other services

I created a Bing Web Search on my Azure Portal. There is no project specific configuration for this service.

Additionally, I created the Bot in Azure Portal. You just need to create the bot and grab the keys and ids.

4. Coding the bot

The whole project is written in C#. I used the standard Visual Studio bot template as a starting point.

First of all, let’s modify the Post activity:

Next, let’s look at the RootDialog class:

Here I am getting the LUIS configuration from the config file and forwarding to the LuisDialog.

The LuisDialog class looks as follows:

I created two main methods: Search and Greeting which will be called based on the intent recognized by LUIS.

The Greeting is very straightforward – it just replies to you with the hard-coded welcome message. You could add here some sample queries and describe the general bot idea and usage.

In the Search method I am configuring the QnA Maker service and forwarding to the QnADialog.

The QnADialog looks as follows:

I added a reference to Microsoft.Bot.Builder.CognitiveServices.QnAMaker. Therefore, I can override the ‘RespondFromQnAMakerResultAsync’ method (line 20) and customize that as needed. If the response with the score high enough (0.8) is found, then post it to user. If not, use Bing Web Search Service.

Here is how I created Bing Web Search Service:

In line 14 I am executing the GET request to the service. Then, I display Hero Cards within a Carousel (lines 26-49) back to the user.

Bot in action

Greeting the bot results in the expected answer:

Hi from Bot

Next, asking a specific question with different syntax returns the answer from QnA Maker:

Replies from bot

The cool thing about the Microsoft.Bot.Builder.CognitiveServices.QnAMaker library is that it handles multiple responses. If more than one result from QnA Maker has good score, then the service suggests more specific questions:

Multiple responses from Bot

Finally, if we ask a question which does not exist in the QnA Maker database, we get Bing results:

Reply from Bot with BING results

Summary

Bots will get more and more popular. Thanks to the Microsoft Bot Framework and Cognitive services you can easily create a bot and a great conversationalist. There are great ideas for Bots in the internet and the list goes on and on.

For further reading about AI I recommend this good article on our blog post: AI and I – Human Artificial Intelligence Relationships.

Happy botting!

Summary
Microsoft Bot with LUIS, QnA Maker and Bing Search
Article Name
Microsoft Bot with LUIS, QnA Maker and Bing Search
Description
Bots are good candidates for answering all the questions you have. See how you can use Microsoft Bot Framework to create a Q and A section for your company, a product, a service or anything you like.
Author
Publisher Name
Atos Consulting CH
Publisher Logo
Mateusz Orlowski

Mateusz Orlowski

Senior SharePoint Consultant at Atos Consulting CH
I work with SharePoint and everything around it.
I have all the SharePoint/Office 365 certificates which gives me super powers.
I read ULS logs in notepad.
I would be an MVP but I have added too many hateful comments on MSDN forum.
Mateusz Orlowski

Latest posts by Mateusz Orlowski (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *