CHATBOT- AI in your hands

World is evolving faster, we can see AI everywhere. One of the greatest examples is launch of Alexa & Google home. They are creating buzz around the people.

Let’s get into world of AI, we are going to develop our own bot. There are many types of bot, popular once are “Rule Based Bots” and “Generative based Bots”.

Rule Based Chatbot: In a rule-based approach, a chatbot answers your questions based on some rules on which it is trained on. The rules on which it works can vary from simple to very complex. In rule based, intent and entity of the question is found and on that basis user gets the answer.

Generative Based Chatbot: This is type of bot which requires lots of training data as it is mainly developed with deep learning models. We can develop a generative based chatbot using simple RNN( LSTM) model.

Generally, most of the problems can be solved using a rule based approach.

Today, we are going to develop a Rule based bot. We are going to use Microsoft Azure Services to build this bot. Microsoft Cognitive services provide lots of API’s like Vision API, Knowledge API (QnA Maker), Language API (LUIS), Speech API & Search API (Azure Search).

Vision API: Image-processing algorithms to smartly identify, caption and moderate your pictures.

Knowledge API: Map complex information and data to solve tasks such as intelligent recommendations and semantic search.

LUIS: Allow your apps to process natural language with pre-built scripts, evaluate sentiment and learn how to recognise what users want.

Speech API: Convert spoken audio into text, use voice for verification or add speaker recognition to your app.

Search API: Add Bing Search APIs to your apps and harness the ability to comb billions of webpages, images, videos and news with a single API call.

INTRODUCTION:

We are going to use below components for our chatbot:

  1. Bot Framework: The Microsoft Bot Framework helps us to build, connect, deploy, and manage intelligent bots to naturally interact with your users on a website, app, Cortana, Microsoft Teams, Skype, Slack, Facebook Messenger, and more. Get started quick with a complete bot building environment, all while only paying for what you use. We are going to write our code in dot net.
Image for post
Image for post
Bot Framework Architecture

2. QnA Maker: QnA Maker is an easy-to-use web-based service to train AI to respond to user’s questions in a more natural, conversational way. We can build, train and publish a simple question and answer bot based on FAQ URLs, structured documents, product manuals or editorial content in minutes.

Image for post
Image for post
QnA Maker

3. Microsoft Azure Services: Microsoft Azure is a cloud computing service created by Microsoft for building, testing, deploying, and managing applications and services through a global network of Microsoft-managed data centers.

Note: Azure account starting is free, plus you get a ₹13,300 credit to spend in the first 30 days. You will not be charged — even if you start using services — until you choose to upgrade.

PLAN FOR BOT DEVELOPMENT:

We are going to follow below step for the chatbot creation:

1. Creating our knowledge base in QnA Maker & Microsoft Azure account creation

2. Creating Web bot service in Microsoft Azure

3. Setup of Visual studio

4. Setup Bot Framework

5. Integration of Bot Framework with Azure services and QnA Maker

6. Chat with the Bot

1. Creating our Knowledge Base using QnA Maker & Microsoft Azure account creation:

Go to https://www.qnamaker.ai/ and sign in:

Image for post
Image for post
QnA Maker Home page

Now click on “Create a knowledge base “:

Image for post
Image for post
QnA Maker Homepage

This part consists of 5 parts are as follows :

Image for post
Image for post
Creating a Knowledge Base

Step 1: Create a QnA service in Microsoft Azure. When you will click on “Create a QnA Service”, it will take you to Microsoft Azure page and you have to create a new Knowledge based service

Image for post
Image for post
Microsoft Azure page

Now provide all the details to create QnA Service:

Image for post
Image for post
Creating QnA Maker Service

Once service is created you can Connect your QnA service to your KB from step 2 in QnA maker page:

Image for post
Image for post
QnA maker Step 2 for knowledge base creation

Now provide name of your Knowledge Base in step 3:

Image for post
Image for post
Providing Knowledge base name

Now provide the Knowledge base in step 4. It can Extract question-and-answer pairs from an online FAQ, product manuals, or other files. Supported formats are .tsv, .pdf, .doc, .docx, .xlsx, containing questions and answers in sequence. You can also add the Question & Answer manually. I have created my own Question and Answer and created a bot for Mall, you can you this URL to get FAQ https://docs.microsoft.com/en-us/azure/bot-service/bot-service-resources-bot-framework-faq?view=azure-bot-service-3.0 .

Image for post
Image for post
Adding Question and Answer

Now click on “Create your KB” to create your knowledge base at step 5

Image for post
Image for post
Creating KB

Here my knowledge based is created:

Image for post
Image for post
Verification of KB

Now you can test your knowledge base by clicking on TEST button:

Image for post
Image for post
Testing Knowledge Base

You can do lots of thing in knowledge base, like adding more questions, modifying your questions & adding similar kind of question for an answer etc. It makes the bot more efficient. You can refer to QnA maker documentation to learn more about it.

Now click on publish tab and publish your knowledge base and you get below details:

Image for post
Image for post
Publishing Knowledge Base

2. Creating Web bot service in Microsoft Azure:

We are done with QnA maker setup now. Let’s go to Microsoft Azure account and click on create resource -> AI + Machine Learning -> Web App :

Image for post
Image for post
Creating Web App Bot Services

Now you can access your Web App bot by clicking on Web App Bot i.e Assistant bot here :

Image for post
Image for post
Accessing Web App Bot

3. Setup of Visual studio:

Go to the location https://visualstudio.microsoft.com/vs/older-downloads/ and download Visual Studio 2015

4. Setup Bot Framework:

Go to your App web bot -> click on build -> click on Download zip file

Image for post
Image for post
Downloading Zip file

Once it is downloaded, unzip it and open Microsoft.Bot.Sample.QnABot

Image for post
Image for post
Click on Microsoft.Bot.Sample.QnABot

Here is the visual studio:

Image for post
Image for post
Visual Studio

Message Controller: A Message Controller helps the user and bot to get connected. When the user responds first the message goes to message controller then it will help to connect with dialogs.

Dialog: A dialog specify the action to be taken by bot on receiving a message from the user.

Now go to dialog-> BasicQnAMakerDialog.cs

Image for post
Image for post
BasicQnAMakerDialog.cs

Microsoft have done some changes in the services and syntax of the code. You can copy the below codes and paste it to the BasicQnAMakerDialog.cs :

5. Integration of Bot Framework with Azure services and QnA Maker:

Now go to Web.config and add MicrosoftAppId, MicrosoftAppPassword , AzureWebJobsStorage, QnAEndpointHostName , QnAAuthKey & QnAKnowledgebaseId :

Image for post
Image for post
Web.Config page

MicrosoftAppId, MicrosoftAppPassword & AzureWebJobsStorage can be found at Web App Bot -> Application Setting as shown below:

Image for post
Image for post
MicrosoftAppId, MicrosoftAppPassword & AzureWebJobsStorage

QnAEndpointHostName , QnAAuthKey , QnAKnowledgebaseId can be found in end of step 1 :

Image for post
Image for post
Published Key

Now provide QnAEndpointHostName , QnAAuthKey , QnAKnowledgebaseId at Web App Services -> Application Setting

Image for post
Image for post
QnAEndpointHostName , QnAAuthKey , QnAKnowledgebaseId

Now go to the Visual studio and click on rebuild

Image for post
Image for post
Rebuilding project

Once rebuild is done go to Microsoft Azure -> App Service

Image for post
Image for post
Microsoft Azure Page

Click on the Get publish profile, your password will get downloaded:

Image for post
Image for post
Get publish profile

Now go to visual studio and click on publish as shown below:

Image for post
Image for post
Publishing the project
Image for post
Image for post

It will ask for password, open Get publish profile and get the password as shown below:

Image for post
Image for post
Provide publish profile Password
Image for post
Image for post
Getting password for publishing project

Once the bot get published successfully, go to Microsoft Azure -> Web App Bot -> Channel , shown below:

Image for post
Image for post
Channel for publishing Bot

Click on skype and login add it to your skype id:

Image for post
Image for post
Page to Add skype account

6. Chat with the Bot :

Image for post
Image for post
Time to chat
Image for post
Image for post

Github: https://github.com/ranjan-sumit/Chatbot-DotNet

Happy Learning !! 😊

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store