Learn About Microsoft Bot Framework

Introduction 

 
We might have come across many situations in our day to day life where we didn’t realize it, but we must have talked to a bot somewhere in the chatbox which was able to solve our problem without any human interaction involved. If you're still wondering... how about Siri, Cortana or maybe even a Domino’s pizza order which we see on their site and we were able to order our pizza with the help of an automated Bot who was there to take our order and we were able to tell him that we want a Farmhouse or Margherita flavored pizza.
 
That's where Bots came into the picture which could understand the instructions and react to those instructions. In this series of articles, we will try to develop that type of small bot that can greet us and remember our name. How cool is that.... let’s dive into it, but first, we need to understand the bots and technology which we are going to use.
 

What is a Bot?

 
A bot is an application that performs an automated tasks in the form of activities without having a human involved. For example, a chatbot. As I told you earlier, Dominos has its own Bot that runs successfully as a campaign, where we can text a Pizza emoji to a specific number and they will, in turn, deliver us a pizza. What makes it run is the Bot Technology. Another example is Siri in an iPhone, or Cortana for Windows, etc.
Learn About Microsoft Bot Framework
 
As you can see, one bot is responsible to answer automated reply on chat. So, bots could be used for this purpose and we can use AI to make them understand the intentions of a person who is talking to it.
 

How do Bots Communicate?

 
Now, let us talk about how exactly bots communicate. We just talked about the bots like what they are and for what purpose they could be used in the market but what do they look like from a software development point? That is the question you might be having. So, to answer this question. Let's just talk about how they communicate.
 
Well, on one side, we have our customers, or you can say users, and on the other side, we have out bot and in order to communicate with each other, they need something, which is called the channel. Channel is nothing but a medium through which bot communicates with the user. Now, there are lots of channels available in the market like teams, slack, Facebook messenger, etc.
 
So, when a user talks to Bot over teams or any channel through the keyboard, the channel exposes an API that will send out a message when a user types something in and receive messages in whenever it gets a reply. This allows it to talk to bot and bot also exposes an API, through this API, our bot can receive messages from user funneled through the channel. And in result, sends a message back to the user through that channel. So, API on both sides which is exposed, on channels and on bot makes it easy to understand what they want and what needs to be sent. That is how they communicate with each other.
Learn About Microsoft Bot Framework

Bot Evolution

 
Now there are many ways to build a bot for any purpose which you might have with you over the years, the technologies and methods have changed and evolved. Now in very starting, bot used to be in a very simple form, which you can imagine as text word to number form. This form used to send a keyword to a medium to perform or execute any action. For example, texting a word adds to a coupon service in order to be put on the mailing list, which was based on only one form and it was designed that way to only accept the limited number of keywords.
 
The main advantage of Bot Framework is that it supports multiple environments by only using a single code base. So, your Bot can be integrated with channels like Facebook, Slack, Teams, etc., and do the task for you. Along with making the data easier to read, it also makes the data going out easier to create with supports for rich attachments. This means that if I want to send an image carousel to Slack, it will be the exact same code as the image carousel I built for Facebook. Finally, the Microsoft Bot Framework can tap into Microsoft's natural language processing framework, which means that creating a bot that can understand natural human language just becomes super simple.
 
The second was a bit of a complex form in which the often-used custom messaging including things like buttons and hyperlinks but still it was keyword based. Now this one is hardest one compared to other two, now we must account for more than one medium, which means you must be ready to account multiple APIs, one for each medium, plus multiple custom message types because each medium has a different way of accepting data structure when we send it back to them. The only thing which is in common is that it’s still keyword based so our logic is going to be straightforward.
 
The third and the last one form gets multiple mediums and a natural language as well. But rather than writing everything from the scratch, it is good to use Microsoft Bot Framework. Microsoft Bot Framework is an SDK introduced in 2016, which we can use for all these tasks. Right now, version 4 is there as the latest and they are working continuously to improve this framework.
Learn About Microsoft Bot Framework

Two Ways To Build Bots

 
I am going to show you just how robust and simple it is to build a fully-featured bot. Now there are exactly two different ways you can start building bots with the Microsoft bot framework. The most robust way is through something called the Bot Builder SDK. This is an open-source SDK that allows you to build a bot using Node.js or C#. The advantage of creating a bot utilizing this method is that it affords you a lot more control over exactly what goes on inside your bot, as well as where you host it. Now the other option is through something called the Azure Bot Service. Now the Azure Bot Service is a service that sits in Azure and allows you to build a bot utilizing templates. The advantage of creating a bot utilizing this method is that you do not have to worry about hosting or maintenance, it's all done through the Azure service.
Learn About Microsoft Bot Framework

Connector Service and Activities

 
In order to make our bot work, we must understand the concept of connector service and activities. So imagine we have one channel on one side and we have a bot on the other side and to make it possible for a bot to communicate to the channel, we have to use Microsoft control service that sits between our bot and the channel. As we know that channel produces its own kind of JSON, and this JSON is sent back to Microsoft control Service And it converts this JSON to an activity. Now, this activity is an object which is used to communicate between the user and a bot. There are several properties that we can use to control our message and how it is presented to the user.
Learn About Microsoft Bot Framework

What is an activity?

 
Let us learn about an activity. An activity is one of the core building blocks of the bot framework. Whenever the user interacts with a bot it generates and activity. Usually, this comes in the form of a message which is nothing but the instruction to perform the task to the bot. Each object of Activity contains activity types which tell the bot about the data which the user might be asking or what to do with this object.
 
Below are the 15 types of activity which come with V4 of bot framework,
 
Activity Type
Description
Message
Communication between Bot and User.
ContactRelationUpdate
When the bot is added or removed from a user’s list.
ConversationUpdate
Bot or other members added to a conversation or metadata of conversation has changed.
DeleteUserData
Instruction to the bot to delete any data which it might have stored.
EndOfConversation
Completion of conversation
Event
Background Communication sent to the bot which is not visible to the user
InstallationUpdate
Installation or uninstallation of a bot within the organization unit like customer tenant or team.
Invoke
Type of communication that is sent to the bot to perform any specific task or operation. Microsoft Bot Framework reserves it for internal use.
MessageReaction
This indicates that the user has reacted to an existing activity. For example, the User clicks on the “Like” button.
Typing
This indicates that user or bot is compiling a response
MessageUpdate
Any update on any previous message activity in a conversation.
MessageDelete
Any deletion on any previous message activity in a conversation.
Suggestions
This tells a private suggestion to the recipient about another specific activity.
Trace
A bot can log the internal information of the conversation transcript.
Handoff
Kind of transferring of the control from the bot to the user about the conversation.
 
So it's just a starting point and we should at least know some background before we actually implement anything. That is what I do mostly to figure out what actually I want first and then what I can use for my needs. In the following blog, I will talk more about States and one actual working example of sample Bot. So stay tuned.... :)


Similar Articles