Building bots with Microsoft Bot Framework

--

About

Bots are a kind of program that automates a lot of things. Usually these are repetitive and easy tasks that are time-consuming for humans. Bots are used for trading, auctions, conversations etc., where they can perform tasks much faster than a human being. In this article we will have a closer look at conversational bots.

Every day a lot of people spend time on their jobs answering the same questions and providing the same information for clients. A good example of this type of job can be shopping chats, support services and others alike. No one wants to wait for a free operator to ask something simple. For example, you will always ask the same questions when you would like to order a pizza. These would concern things like type, size, quantity and delivery. This kind of person-to-person conversations can be replaced with bots that can help your company to concentrate human resources on more complex and non-trivial tasks.

Conversational bot is not a new thing, but now their development has become as easy as never before. In 2016, Facebook and Microsoft announced their bot platforms. It means that top companies are interested in this direction and will take a lot of efforts to popularize Conversational User Interfaces (CUI) as an addition of well known Graphical User Interfaces (GUI).

Creating a bot

To demonstrate you how to build a bot we will use Microsoft Bot Framework (MBF). MBF was announced in March on the Microsoft developers conference BUILD 2016. MBF is not just a framework your developers can use to create a bot. It is also a platform that can help you to integrate your bot with other services like Skype, Slack and others. We also expect that in future you will be able to publish your bot and earn on them like now companies make money on stores like AppStore or Google Play.

Right now there are two ways to create a bot on MBF. You can create a new bot with Bot Application Template for Visual Studio(http://aka.ms/bf-bc-vstemplate) or add it to your existing project. We will use the second approach and add a bot to default ASP.NET MVC application.

Steps:

1) To start working with MBF you will need to install Microsoft.Bot.Builder Nuget package that will add all necessary libraries to your project.

2) To take a message from the user and create a reply you will need to create new API controller.

3) For processing dialog, we will use Dialogs model.

Dialogs model a conversational process, where the exchange of messages between a bot and a user is the primary channel for interaction with the outside world. Each dialog is an abstraction that encapsulates its state in a C# class that implements IDialog. Dialogs can be composed with other dialogs to maximize reuse, and a dialog context maintains a stack of dialogs active in the conversation.

Microsoft Bot Framework Documentation

For processing the basic dialog you can use your implementation of Dialog interface. The dialog should be a serializable class because the state of Conversation is transferring every time during conversation through Json. In order to demonstrate how it works we will create a simple dialog for asking users to answer a simple math question.

4) The Bot Framework also provides an emulator that lets you test your bot. You can download Bot Framework Emulator here.

Publishing

Let’s publish our bot to Bot Framework developer portal and make it working on Slack.

Steps:
1) Make your website available to direct access. We have deployed our website to Azure.
2) Create your bot on Bot Framework developer portal here.

3) You will have your bot webpage. Here you can change settings, test your bot or integrate it with other platforms. To integrate your bot in Slack just press Add near Slack and follow instruction

4) Congratulations. Your bot is successfully working on Slack

Summary

If your company spends a lot of money on talking to clients, you can try to build a bot. Of course it will not replace you a human for non-trivial tasks, but you can use them for a lot of regular tasks. The era of Conversational User Interfaces is near so be one of the first who enter it.

Originally published at www.westcoup.com on April 25, 2016.

--

--