Get chatty with Microsoft Bot Framework

04 mei 2020 om 10:53 by ParTech Media - Post a comment

Today, things, like ordering food or booking a hotel room, are just one tap away from you. But, some traditional user may complain that this all online ordering or booking experience lacks a personal touch. So, to overcome this hurdle, user are often presented with a solution in the form of chatbots.

A chatbot is a computer generated program to stimulate conversation with human users over the internet. There are plenty of different options available to create chatbots ready for your website or app, but we are going to focus on the framework that Microsoft provides us with: Microsoft Bot Framework.

Overview of Microsoft Bot Framework

Azure Bot Service and Bot Framework is a complete package of tools that helps in building, testing, deploying and managing the bots. By using the extensible framework and advance modular developers can create highly functional bots with features like speech, understanding different languages, answering multiple queries and so much more. All these features are offered by various SDK, tools, AI, and templates bundled up in this one framework.

In this bundled Bot Framework pack multiple things are included such as the

  • Bot Framework SDK to develop feature-loaded bots.
  • Bot Framework Tools used to sustain an end to end bot development process.
  • Bot Framework Services, helps in sending and receiving messages between bots and channels.
  • Azure Configuration to configure bot deployment and channel in Azure.

Key highlights of building bots

Before we step up and introduce the simple process of developing bots using the Azure framework, we want to introduce you with some of the highlights that you should consider before building a bot.

Channels

It is the part that enables users to communicate with the bot. A channel is a communication pathway between a bot and communication programs such as Slack, Facebook Messenger or web chats. Once the core logic of the bot is ready, then Channels are used to publish it.

img

Source – Microsoft

Conversation Flow

To create a personalized experience for users, a bot should say more than just a “hello”. To set up a simple and elegant flow of conversation, developers need to use a collection of dialogues. These sorts of structures in the bot are designed to perform operations in a certain manner. For instance, the operations can be invoked when LUIS identifies an intent - of the user's response or other dialogues.

img

Source: Microsoft

Media and Cards

When a developer want to design conversation in an interactive manner rather than just plain text, then the media and cards come into the highlight. Using Azure Bot Framework, rich control features can be added in the bot such as buttons, menus, images and other navigation gestures to make a smooth conversation.

img Source: Microsoft

Bot Framework Emulator

To test the bot by publishing it on Azure, the Bot Framework Emulator is used. It allows developers to evaluate the underlying services that bot contains using the Bot Explorer. Moreover, in the Visual Studio, the user can start emulator to point of bot URL and know when chat takes place and much more.

img

Source: Microsoft

Templates

Templates are used by Azure Function to control the logic. There are plenty of different templates available that speed up bot development process such as:

  • Form Bot – This template can define questions that developers want to ask via chatbots without going through the trouble of building multiple if and else conditions.
  • Proactive Bot – It is a very interesting bot powered by Queue Trigger Azure Function that will greet customers on their birthdays or offer deals on special occasions.
  • Question and Answer Bot – This bot will answer based on the question input.

Process of Building a Bot

As we covered some of the common things that you need to develop a basic bot, then next it is time to understand the process of building a bot. Creating a bot is a very simple process and the entire process is presented in an easy manner. The basic bot with the feature of tracking down messages that you have received and display information in the chat window can be developed with the help of Visual Studio and .NET Core 2 (or higher).

img Source: Microsoft

In this post, we won’t map out a detailed line of code for you as you can get full source code on Microsoft website, but we will focus on the key elements of the code here:

BotConfiguration.bot

This handles the bots endpoints. The bot configure file is uploaded into the emulator.

img

Source: Microsoft

SimpleWithCounterBot

It is underlining logic that has the potential to give power to the bot. Whenever a message is sent by the user, then the OnTurnAsync method present in the class is automatically invoked. The key logic can be used here along with some comments that have been detailed in the underlying logic. The state variable will be also created here that lets your bot store the information on how many times a user has sent a message.

img Source: Codematters

Bot Accessors

The best thing here would be to encapsulate the state variable into the Accessor class. The developer should primarily look for the CounterState that contains a property name TurnCount. This is the property that developers use in the main logic to calculate the number of turns a user has taken.

img

Source: Codematters

Operate the chatbot

Using the basic information, you can use the bot:

  • Just enter your message
  • Increments a TurnCount variable to track the “turn” you’re on
  • The message you have entered will echo back
  • Now, wait for the next message

Here, when you operate the solution in Visual Studio, then your browser will show you how the bot is operating and at which point you can run the Bot Emulator. You will be able to interact with your bot easily.

Conclusion

From understanding key pointers of Microsoft Bot Framework to going through the basic process of building a bot, we have just touched the surface of the topic. The is a very intelligent communicator and can be implemented to perform multiple processes such as understanding various languages using LUIS, extract entities from a sentence and continue the conversation with the relevant dialogues.

However, it is a detailed process that can’t be explained in the nutshell so stay tuned with us to dwell more into the topic.