Microsoft Chat Bot - Tips And Tricks

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 chatbot applications. In this article, we are developing a simple chatbot application using ASP.NET Core 3.1 with Core Bot Template.
 
Note
We have published the detailed description of Chatbot conversational AI as a free E-book ( March 19 / 2021 ). We have added the link to the e-book in the reference section please read before diving into this article.
 

Bot Framework

 
The Bot Framework has the capability to build a high standard and rich enterprise conversational AI experience for 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 chatbot with all kinds of AI features like Cognitive Services, QnA Maker, Luis, etc. There is much confusion on which situation we should use all these AI features in chatbot development. So going forward we will understand in which situation this feature is more helpful for the chatbot conversational flow.
 
As of now by default Visual Studio does not contain any Bot Framework in the template section. The SDK is available for Bot Framework template integration in Visual Studio, please click here to download and install the latest SDK for Bot Framework in Visual Studio.
 
Microsoft Chat Bot
Image source: https://rajeeshmenoth.wordpress.com/

Azure Bot Service

 
First of all, don’t be confused about Bot Framework and Azure Bot Service, As we discussed earlier Bot Framework SDK includes a 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 the Azure Cloud environment for public access using a single service or an endpoint call. There are many channel integrations available in Azure Bot Service for interactive communication in chatbot applications. The available channels are MS Teams, Slack, Messengers, etc.
 

Conversation Workflow

 
The below diagram is one of the examples of chatbot 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. Most of the Microsoft Bot will use the same pattern for chatbot communication. Now we can dive into each segment that we have used in the following diagram.
 
Microsoft Chat Bot  
Image source: https://rajeeshmenoth.wordpress.com/
 

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 a free Azure Subscription -> Azure Free Subscription
 

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.
 
Microsoft Chat Bot  
 Image source: https://rajeeshmenoth.wordpress.com/
 

Create Web App Bot

 
Once the creation of the Core Bot Template then we can host the application in the Azure environment with the help of Azure Bot Service. Please check our previous article for Web App Bot Creation in Azure.
 
Microsoft Chat Bot  
Image source: https://rajeeshmenoth.wordpress.com/
 
After the creation of Web App Bot, we can host our chatbot application in the Azure environment using Visual Studio publish option. The successful deployment will give you the following result in "Test in Web Chat". Just click on the "Test in Web Chat" menu pane to open the webchat channel for the chatbot testing.
 
Microsoft Chat Bot  
Image source: https://rajeeshmenoth.wordpress.com/
 
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 In-memory storage is basically using for testing purposes so when you are working on production then better to go with the highly recommended Azure Cosmos DB. Why it’s highly recommended because Azure Cosmos DB has millisecond response times, and automatic and instant scalability, guarantee the speed at any scale. Also highly available with enterprise-grade security. These are more important when you are deploying chatbot applications for worldwide usage. We can also use Azure Table Storage for state management.
 
In Memory
 
In Memory is temporary memory and used for testing purposes, The following code we can register in the ASP.NET Core middleware section. 
  1. // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)  
  2. services.AddSingleton<IStorage, MemoryStorage>();  
Cosmos DB
 
Cosmos DB is a very fast distributed, scalable and secure database is using in Azure chatbot, The following code we can register in the ASP.NET Core middleware section. 
  1. services.AddSingleton < IStorage > (c => new CosmosDbPartitionedStorage(new CosmosDbPartitionedStorageOptions() {  
  2.     AuthKey = Configuration["CosmosAuthenticationKey"],  
  3.     ContainerId = Configuration["ConfigCollectionName"],  
  4.     DatabaseId = Configuration["CosmosDbName"],  
  5.     CosmosDbEndpoint = Configuration["CosmosEndpoint"],  
  6. }));   

QnA Maker

 
QnA Maker is a prebuilt AI by Microsoft, It provides a Knowledge Base with Question and Answer Pairs. In the chatbot application, we can consider QnA maker as a database or a Knowledgebase to answer all kinds 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 departments and you want to assure that the selected department ( UI menu selection for asking the respective question) answers are properly getting as a response through a chatbot. This scenario we can achieve in many ways, One is we need to maintain multiple Knowledgebase in QnA Maker for each department. To achieve this scenario we required LUIS for intent ( like category ) identification or department identification. Here the 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 to the E-book in the reference section.
 

Language Understanding Intelligent Service ( LUIS )

 
LUIS is a prebuilt AI by Microsoft, Why we are using LUIS is a chatbot application that we have discussed in the QnA maker section. LUIS will identify the department or intent if the organization have multiple department scenario in an application, this will give a clear picture at the end for which knowledgebase need to be connected 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 to the E-book in the reference section for more detail about LUIS.
 
QnA Maker With Empty Response
 
If QnA Maker didn’t answer the question asked by the user in that we need to handle it 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 unanswered questions from QnA Maker but this is not a good practice for domain bot application for an organization.
 
Live Agent Connect / HandOff
 
Sometimes users want to connect with a human agent or live agent, These are our findings and implementation details.
  • 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.

  • This is the best open-source code for a 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 connectivities in the bot. This will handle multiple user requests to an agent with the help of an agent hub. The agent can open a communication channel for user connectivity. You will get a better understanding once you go through the documents.

  • This is the one I have implemented reference, This will be a simple redirection to an agent from a user with his comments or issues through the Microsoft team channel group. I have implemented one-way communication but at least you can inform the group ( created for the agent team ) of user issues with his account details in the channel in the ms team. So any of the agents in the team can personally contact him through the ms team account and resolve the issues.

Channel

 
Channel is nothing but it’s like a bridge to communicate between the user and the bot application !!
 
As per the definition of Microsoft Docs
 
"The Bot Service provides protocols and APIs 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 currently available channels in Azure Bot Service.
 
Microsoft Chat Bot  
Image source: https://rajeeshmenoth.wordpress.com/ 
 
Channel Configuration 
 
We have already learned about how to configure slack channels in Azure Bot Service Slack Channel Configuration. Now we can learn the most popular “MS Team” channel within simple steps.
 
First, click on the Channels menu pain in our Bot service app and click on the “MS Team” icon.
 
Microsoft Chat Bot  
 Image source: https://rajeeshmenoth.wordpress.com/
 
Then select the respective radio button based on the business requirement and click on save.
 
Microsoft Chat Bot
Image source: https://rajeeshmenoth.wordpress.com/
 
Within a second MS-Team channel configured in our Azure Bot Service with "Running" status. 
 
Microsoft Chat Bot  
 Image source: https://rajeeshmenoth.wordpress.com/
 
Click on the MS Team icon and open the application in either browser or in the 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 just by testing the bot application in the MS-Team channel.
 
Microsoft Chat Bot
Image source: https://rajeeshmenoth.wordpress.com/
 
Note
The best way to host the MS Team channel application at an organization level is you need to create a bot app in the app studio editor part of the ms-team application.
 
MS Team Output
 
Microsoft Chat Bot
Image source: https://rajeeshmenoth.wordpress.com/ 
 
Reference

Summary

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


Similar Articles