Are you new to the Bot development?

A few weeks ago, one of my colleagues was interested in getting to know how to get started with this fancy bot world. Like all the new platforms, there is going to be a learning curve and lots to digest with this ecosystem and it may be hard to understand where to start to efficiently navigate the learning curve and get up to speed real fast.

In this post, I aim to provide you with the information to put you in a right direction to get started with the bot development.

Microsoft Bot Framework

In order to develop your own bot and make it available for your users, as you may have guessed, you need a bot development framework. There are a lot of Bot frameworks available today. By far my favorite among the bunch is Microsoft’s Bot Framework due to the ecosystem it is built on, rapid growth, adoption and the fascinating community behind it. And guess what, it is an open source project.

You can find Microsoft’s Bot Framework website here.

Microsoft recently upgraded the Bot Builder framework to version 4.0 which is available both on .Net and JavaScript. You can find the full documentations here. This documentation is essentially the bible that contains all the different APIs that the bot exposes and teaches how can we create a simple to sophisticated bot. This is where you spend most of your time to understand different capabilities of the bot framework with examples and the best practices which the bot development team themselves learned while working on the framework and samples.

The Bot Framework documentation is extensive and very interesting as it contains day to day examples with clear indication of the best practices. I highly recommend you to quickly skim through the full documentation without getting bogged down by the details and the code samples. Because, it is very easy to get caught into weeds of it and spend a lot of time without necessarily understanding all the intricacies of the bot building.

But, wait, then how do we learn all the details and intricacies? That is where the samples that Microsoft team built come in.

Bot samples

Bot Builder SDK is available both for .Net and JavaScript.

Microsoft team has made a lot of quick bite samples (for .Net as well as JavaScript) to explain all the abilities that the bot framework exposes in order to rapidly host it on our local machine and give it a run to visualize how each ability/functionality works. As these are bite sized and quickly digestible, this is going to significantly flatten our learning curve. This is where you get into all the details of the code and at the same time interact with the bot.

When you review the bot builder sample that interests you, you can find the full explanation of the bod builder sample code in the bot framework documentation and this is the right time to delve deeper in the code and the related documentation that backs each and every functionality. For the first timer, I’d recommend starting with the “Echo with Counter” sample. This is a simple bot that keeps track of the incremented counter with each message from the user.

You can debug and check out which code is executed while you interact with the bot, which greatly helps to divide and conquer the relatively huge framework.

You could ask how would I be able to interact with the bot if I have not hosted the bot on the website or on Messenger, Slack, other channels etc.,?

Emulator

Bot Framework ships with an Emulator and this github page has instructions to download and setup.

After installing and setting up the emulator, we can point the emulator to the locally hosted bot application sample and start interacting with the bot. Ideally, we would want our bot to be deployed on azure, but the emulator will quickly enable us to stand up a bot application and debug any issues before going through the azure deployment process.

Azure Bot Service

Azure Bot Service provides an integrated environment to allows us to build, deploy, test, cognitive services integration and connect to various channels.

As I mentioned before, azure deployment is inevitable and a simple process. We can deploy our bot application right from the visual studio. This article explains the steps involved in detail.

Channels

Before going too far, I need to introduce you to the concept of channels. Channels are various outlets through which your customers can interact with the bot that you develop and deploy.

For example, if we are a pizza bot developer, which our customers can use the bot to enquire options and order pizza, we would want the bot to be deployed on the web chat channel (this is nothing but bot deployed on a website) and we could also consider deploying on Facebook Messenger as we would want our bot to be where our users are. Microsoft Bot Platform supports Facebook Messenger natively, so we can integrate our bot with messenger very easily.

Also, the bot framework supports a few other channels like Slack, Teams, Skype etc., giving us an opportunity to increase the user interaction and reach more customers.

Bot framework allows us to develop the bot in a channel agnostic way. Incase of inconsistency with messages passed between the bot framework and what the channel usually supports, bot framework mostly takes care of converting it in the format that a particular channel supports. Integrating with the different channels is usually configuration driven.

Direct Line Channel

Bot Framework can integrate with various channels such as web application, Skype, Teams, KiK, Slack, Facebook Messenger etc., But there could be scenarios where we would like to integrate the Bot with our native apps or our custom client application or even games. Direct Line API provides us with the capabilities to integrate in such situations using REST or Websockets.

Cognitive Services

If you make yourself familiar with the documentations above, you are well equipped to develop some great bots. But, it wouldn’t hurt to add some artificial intelligence to the bots with the help of Cognitive Services.

There are a bunch of cognitive services available such as Computer Vision, Face Detection, Natural Language Processing, Text Translation, Text to Speech etc., that are pre designed and available to infuse AI into our bot application.

Think of them as super powers that we can accessorize our bot with, to tackle common problems that your business face that only sophisticated algorithm can solve. Cognitive Services is Microsoft’s way to democratize the artificial intelligence.

These Cognitive Services are available as APIs to call and consume within our bot application. Imagine a bot that automatically determine the product based on the product image that our customers upload or imagine a bot that would understand the user’s intent by processing natural language. Wouldn’t that be cool? The importance of these services are increasing day by day as most customers expect the bot to have a degree of intelligence to eventually replace their human counterparts in certain use cases.

The bottom line is think of these services as accessories to our bot. Some accessories are more valuable than others based on our business and the customers that we would like to address. A well equipped accessory will dramatically increase our customer satisfaction and may even reduce our operational cost.

If you ever wanted to start learning about the cognitive services and would like to try integrating with your bot, I recommend learning LUIS (Language Understanding Intelligent Service).

LUIS is a service that takes the user’s input in a natural language and extracts meanings and intents.

Here is a step by step on how the bot interacts with LUIS and vice versa:

  1. User types “Can I know the status of the order number 221?
  2. Bot gets this message from the user, but does not know how to respond to the user unless our bot is hardcoded to always retrieve the status result of the order number regardless of the user’s input. As our bot does not know how to respond, it calls the LUIS api using the configurations present in the .bot file and passes the user’s input as parameter.
  3. LUIS is pre trained to understand the intent for different types of user’s input and as it continuously learns, it identifies that the user’s intent is to “Find the Status of Order“.
  4. LUIS triggers a method in the bot application “FindOrderStatus” which is configured to retrieve the order status from the database.
  5. Finally, the bot responds to the user with the order status.

Another interesting cognitive service is QnAMaker. This service automagically turns a webpage with FAQ (Frequently Asked Questions) into questions and answers that our bot can understand out of the box. Next time, our customers need not skim through 100 different questions on a webpage to find the answer, instead they can interact with the bot with their question to find the relevant answers.

Keywords

It is time to get you started with some fancy new keywords to introduce you to the bot development world.

Turn

People take turn while speaking, so is our bot. Turn provides us a context as to what our bot is supposed to do on each turn someone is speaking. This forms a fundamental part of the bot development. You will work with the “Turn” context on every turn of your bot development.

Dialog

As the name suggest, Dialog is the bot component that allows to provide the conversational experience to our customers.

If we build a hotel booking bot, we will use the “Dialog” component to compose the questions that we want our bot to ask and process the answers that our bot may receive from our customer. Essentially, Dialog helps us to design and control the conversation flow gracefully.

Our Dialog will be defined as 

  • Ask the 1st question to the customer.
  • When the customer responds to the 1st question, process/validate the response and then, ask the 2nd question.
  • When the customer responds to the 2nd question, process/validate the response and then, ask the 3rd question.
  • and so on..

Bot State

Like web application, Bot application is stateless in order to maintain the abstraction and provide scalability.

If the bot asks for the city preference to show the weather, there is no fun in asking it again and again. We expect the bot to remember the customer’s preference to provide the best experience possible. That is where the State comes in. State component allows to store a piece of data that the bot generates or a piece of data that is obtained from the user, so that the data is not lost and need not be obtained again from the user.

As a bot developer, it is our responsibility to write and read the Bot State to the Storage layer of choice (CosmosDB, Azure Blob etc.,).

Middleware

Middleware is not a new concept, but the bot framework makes heavy use of that. It is a separate piece of code that is abstracted from the bot logic and any messages between the bot and the user flows through the middleware. This gives an opportunity for the developer to act on the message if they wish. For instance, if we would like to create a transcript of the full chat conversation, we could create a middleware that just stores the chat transcript in the azure storage. The idea behind the middleware is to create a plug and play kind of software design in the bot development.

Tools

The Bot Framework has its fair share of tools to make the development process both simple and fun.

Enterprise Template

Enterprise template is available to be installed in Visual Studio which will set you up with a number of key functionalities with best practices to build a enterprise grade bot.

Bot Analytics

Like any application, bot application is also served well by analytics. Azure Bot Analytics provides reporting on user retention, number of activities sent and received on channels etc.,

.Bot File

Our bot will have to connect to the Azure Bot service, may process natural language through LUIS, connect to various cognitive services, connect to azure services such as blob, cosmosDB to store state data and so many other services. How does the Bot application manages the connection to these services? This .Bot file serves just for that purpose. It contains all the necessary connection parameters in a central location so managing all the services integration is much more efficient.

Here is a sample of how the .Bot file looks.

Bot CLI Tools

There are a number of CLI (Command Line Interface) tools to streamline the whole development and the cognitive services integration process as defined in the Bot Builder SDK GitHub documentation.

For instance:

There is a tool called ChatDown that allows to create a conversation mockup during the design stage so as to understand the user interaction and gaps before even beginning the development process.

Another tool LUISGen that will help to generate strongly typed C# classes for the LUIS’s intents and entities making the build process smoother.

I’d highly encourage you learn these tools to be efficient with the bot building process. But if you wanted to prioritize the bot development learning process, these tools would not be in the top priority list, in my opinion. Learning the Bot Framework and the concepts that power it will be the priority number 1, all the bot framework accessories such as Cognitive Services integration will be the next in the priority list and then comes all the tools which will complete your learning process.

Final thoughts

Like any new platform, Bot Framework comes with a learning curve to navigate, but as the Bot Framework is built using some of the familiar components such as .Net, JavaScript, Azure Services along with some great tools, Microsoft tries to flatten the curve a little bit so the developers can easily adopt the Bot Framework. The Bot Framework documentation has many practical examples, Do’s and Don’ts to help share the knowledge obtained by the team and community and the bot samples really is a great way to kick start the learning process.

Hope this helps someone who wanted to get their feet wet with the Bot development, but do not know where to start.

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