Microsoft Chat Bot


Introduction

Recent trends show that chatbots are essential everywhere, whether it’s an entertainment, medical, or knowledge-based website. Since this is an emerging technology, developers all around the world will be wanting to know more about this, specifically, what is happening in the background of chat bot applications. In this article we are developing the simple chatbot application using ASP.Net Core 3.1 with Core Bot Template.

Note : We have published the detail description of Chatbot conversational AI as a free E-book last week ( March 19 / 2021 ). We have added the link of the e book in the reference section please read before dive into this article.

Bot Framework

The Bot Framework have a capability to build a highly standard and rich enterprise conversational AI experience to the customers or end users. Also Bot Framework is a highly branded virtual assistant development framework or chatbot development framework by Microsoft. So we can build a chat bot with all kind of AI feature like Cognitive Services, QnA Maker, Luis, etc. There are many confusion on which situation we should use all this AI features in a chatbot development. So going forward we will understand in which situation this feature are more helpful for the chat bot conversational flow.

As of now by default Visual Studio do not contain any Bot Framework in template section. The SDK is available for Bot Framework template integration in Visual Studio, Please click here to download and install latest SDK for Bot framework in Visual Studio.

Azure Bot Service

First of all don’t be confused on Bot Framework and Azure Bot Service, As we discussed earlier Bot Framework SDK includes lot of open source SDK for building conversational AI.

Azure Bot Service is a platform provided by Microsoft to create and manage the chatbot application in Azure cloud environment using a single service or an endpoint call. There are many channels integrations available in Azure Bot Service for the interactive communication in chatbot application. The available channels are MS Teams, Slack, Messengers, etc.

Conversation Work flow

The below diagram is one of the example of chat bot conversational flow which means we can consider any type of flow as per our business requirement and this is one of the POC of conversational flow. The most of the Microsoft bot will use the same pattern for chatbot communication . Now we can dive into each segments that we have used in the following diagram.

Azure Subscription

A valid Azure subscription key is required for the creation of any of the services in the Azure portal. We can create an Azure subscription in multiple ways, either a free or paid service.

Please click here to create free Azure subscription -> Azure Free Subscription

Active Directory

There are many world-wide users communicating with the chatbot application, sometimes this will create a security attack and it create major problems in all the applications not only in chatbot. The AD or Active Directory is an enterprise identity service provides single sign-on ( SSO ) and multi-factor authentication to help protect your users from 99.9 percent of cybersecurity attacks. Also this is more helpful for managing an user in an organization with the help of azure environment.

Note: The security is more concern about all customers in world-wide and also expecting a highly availability so this we can achieve in azure environment without any single doubt.

App Registration

Within Azure Active Directory we can find out App registration, This will be more helpful to assign a large number of permission into the registered application inside the AD. I think everyone are familiar about Graph API, using this API we can give two levels of permissions ( Delegated & Application Level ) in a registered application in azure app registration pane. When you are developing a chatbot for internal organization or private communication inside the organization then those kind of scenarios we can handle through Graph API user level permission. Apart from that we can prevent the unauthorized user access and implement a role based ( Graph API can provide a complete user details in a AD) communication & permission in a chatbot application.

Note : As we have discussed earlier we need to create an Azure Bot Service in Azure environment , This will automatically register chatbot application in an App registration section included Bot channel registration. Please check our previous article for Web App Bot Creation in Azure.

Core Bot Template

We are using VS 2019 and Installed Bot Framework SDK V4 in our system environment. As you can see this chatbot application developing top of .Net Core 3.1 using C# with all AI features. By default it will provide LUIS ( Language Understanding Intelligent Service) code in the Core Bot template.

Visual Studio 2019 -> Bot Template

Create Web App Bot

Once after creation of Core Bot Template then we can host the application in azure environment with the help of Azure Bot Service. Please check our previous article for Web App Bot Creation in Azure.

After the creation of Web App Bot we can host our chatbot application in Azure environment using Visual Studio publish option. The successful deployment will give you the following result in “Test in Web Chat”. Just click on “Test in Web Chat” menu pane to open web chat channel for the chatbot testing.

Channel Configuration

Channel is nothing but it’s like a bridge to communicate between user and the bot application !!

As per the definition of Microsoft Docs :

“The Bot Service provides protocols and API’s through which you can connect your Bot to the services where your customers are. A channel represents the service you wish to reach your users on, such as Skype, Microsoft Teams or Facebook.”

These are the current available channels in Azure Bot Service.

Channel Configuration

We have already learned about how to configure slack channel in Azure Bot Service Slack Channel Configuration. Now we can learn the most popular “MS Team” channel with in simple steps.

First click on the Channels menu pain in our Bot service app and click on the “MS Team” icon.

Then select the respective radio button based on the business requirement and click on save.

Within a second MS Team channel configured in our Azure Bot Service with “Running” status.

Click on the MS Team icon and open the application in either browser or in MS Team application in your system. If the bot is not replaying with the welcome message then just try to enter one message.We are doing this for just testing the bot application in ms team channel.

Note : The best way to host the ms team channel application in an organization level is you need to create a bot app in app studio editor part of ms team application.

OUTPUT

Middleware

In Asp.Net Core, Middleware is software that is assembled into an app pipeline to handle requests and responses. So here we are registering all the chatbot related services like Storage, IBot, User State, Conversation State and other services as well.

The below example is state that “IBot” is inherited to “DialogAndWelcomeBot” and again this internally inherited into “ActivityHandler” and many more , we need to resolve this dependency using the middleware registration. The Ibot is the initial triggering point of chatbot application.

Example :

services.AddTransient<IBot, DialogAndWelcomeBot<MainDialog>>();

Storage

Managing the state is the vital role of communication in all kind of application not only chatbot, So how we can store the state in chatbot application, It’s pretty simple because Bot framework is provided by default package libraries for storing the state in Azure or InMemory.The Inmemory storage is basically using for testing purpose so when you are working on production then better to go with highly recommended Azure Cosmos Db. Why it’s highly recommended because Azure Cosmos Db have millisecond response times, and automatic and instant scalability, guarantee speed at any scale. Also highly available with enterprise-grade security. These are more important when you are deploying the chatbot applications for world wide usage. We can also use Azure Table Storage for the state management.

In Memory :

 // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
 services.AddSingleton<IStorage, MemoryStorage>();

Cosmos Db :

services.AddSingleton<IStorage>(c => new CosmosDbPartitionedStorage(new CosmosDbPartitionedStorageOptions()
            {
                AuthKey = Configuration["CosmosAuthenticationKey"],
                ContainerId = Configuration["ConfigCollectionName"],
                DatabaseId = Configuration["CosmosDbName"],
                CosmosDbEndpoint = Configuration["CosmosEndpoint"],

            }));

QnA Maker

QnA Maker is a prebuilt AI by Microsoft, It provide a Knowledge Base with Question and Answer Pairs. In chatbot application we can consider QnA maker as a database or a Knowledgebase to answer all kind of questions that we have already added in the QnA Maker Knowledgebase. These are predefined questions & answers adding by users themselves.

For Eg, In an organization if you have multiple department and you want to assure that the selected department ( UI menu selection for asking respective question) answers are properly getting as response through chatbot. These scenario we can achieve in many ways, One is we need to maintain multiple Knowledgebase in QnA Maker for each departments. Achieve this scenario we required LUIS for intent ( like category ) identification or department identification. Here intent is considered as department and inside the intent we can add utterances or questions for the department identification. Based on the intent we can deviate the respective Knowledgebase call in Qna Maker. another way to achieve this scenario is Luis dispatcher so please refer the E-book in reference section.

Language Understanding Intelligent Service ( LUIS )

LUIS is a prebuilt AI by Microsoft, Why we are using LUIS in a chatbot application that we have discussed in QnA maker section. Luis will identify the department or intent if organization have multiple department scenario in an application, this will give a clear picture at the end for which knowledgebase need to be connect inside the Qna maker. Here intent we can consider as department and inside the intent we can add utterances or questions for the department identification. So please refer the E-book in reference section for more detail about LUIS.

QnA Maker With Empty Response

If Qna Maker didn’t answer the question asked by user in that we need to handle in a tricky way either we need to display generic messages like

“Sorry, We are unable to answer your question and could you please rephrase it”

Another way is connecting to Bing Search API, Google Search API, etc for un answered question from qna Maker but this is not a good practice for domain bot application for an organization.

Live Agent Connect / HandOff:

Sometimes user want to connect a human agent or live agent, These are our findings and implementation details.

  1. As per the github documentation from Microsoft, I understood that there is an experimental package available for handoff in C# code ( Microsoft Handoff library ). As of now this library is not recommended for production use and please check this experimental docs reference for more info and below comments in the github account :

The samples in this folder should not be used in a production environment. They are not supported and the team is not implying a given approach used in these samples will be integrated into a future version of the Bot Framework SDK. Instead, we want to provide a way to engage on topics that can help guide our roadmap for future work.

  1. This is the best open source code for live agent ( handoff library ) that I found from github. The author of the code is an approved microsoft open source contributor and he has developed an agent hub routing + multiple channel connectivity in the bot. This will handle multiple user request to an agent with the help of agent hub. The agent can open a communication channel for user connectivity. You will get a better understanding once you go through the documents.
  2. This is the one I have implemented reference, This will be a simple redirection to an agent from an user with his comments or issues through microsoft team channel group. I have implemented one way communication but at least you can inform to the group ( created for agent team ) for user issues with his account details in the channel in ms team. So any of the agent in the team can personally contact him through ms team account and resolve the issues.

Reference

Summary

From this article we have learned the important background process and implementation of chatbot application.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: