Archive for March, 2018

Understanding Azure Chat bot

Posted: March 23, 2018 in Uncategorized

In the next blog posts I will go through the different components of the Azure Chat Bot and how can you benefit from it in your application.

First of all, you can consider the chatbot is like your application but with different interface. Its main target is to facilitate the workflow for your users in a conversational format. Most of the chat bot available online is to make it easier for your users to make it easy to submit a new order for your product. One of the great benefits of the chat bot is it will give your application the ability to reach your customers through different channels easily just by some configuration on your chat bot. Also the Bots are able to communicate with your users using different formats that you can define whether using text, UI, like the HeroCard, and even using speech.

In the following picture that I got from Microsoft Website to showcase the similarity between the traditional application and the bot application.

In this blog post, I will clarify the different components of the libraries that you can use to build the bot application and its workflow. So for the Microsoft Chat Bot, they have done some work decoupling the services that you will need to work with to build your bot. There are 2 main libraries that you will be using to develop the application using the .Net:

  • The Bot Connector (.Net Library)
    • This library is mainly used to connect your bot to your channels and vice versa using the REST API. The Connector then uses the Activity object to pass the information from one side to another. There are some predefined channels that you can use to develop your bot application like Skype, Twililio and others… If you don’t see the desired channel you can start by using the Direct Line API to communicate between the Bot connector and your channel.
  • The Bot Builder (.Net Library)
    • The bot builder library is mainly used to develop your bot application whether by a guided conversation (FormFlow) or by understanding your user intention for example. The Bot Builder library has different sub libraries that helps you create the convenient bot application for your users.
  • Now for the bot application state, the bot framework is providing some services for the working with your bot state In-Memory, however for production environment it is definitely recommended that you use some storage to store your chatbot state like the Azure Cosmos DB or the Azure table storage.

Talking about the storage that you can use for your bot, there are some predeveloped functions that you can use to store the details of the application. There are some Azure Extensions for the azure table storage and the azure Cosmos DB shared in the following GitHub for both .Net and Node.js

Just a quick walkthrough for the Azure Chatbot integration with the different type of storage even if it is InMemory, you can use the following code to define the what you want to implement:

//azure cosmos DB


var cosmosdb = new DocumentDbBotDataStore(uri, key, databasename, collectionname);


//azure table storage


var tablestorage = new TableBotDataStore(new CloudTable(tableuri));


//InMemory


var inmemory = new InMemoryDataStore();

 

then you can keep updating the status of the conversation with the following code, just change the cosmosdb with the desired attribute for the storage you are willing to work with:

Conversation.UpdateContainer(builder =>

{

builder.Register(c => cosmosdb)

.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)

.AsSelf().SingleInstance();

});

 

Don’t forget to download the ChatBot emulator that you can use to test running your application locally.

In the following GitHub links, there are Microsoft Chatbots code that you can work with and understand how the chat bot really works with some real demos using .Net, and I am also sharing some of the work that I have done using .Net for the chatbot that I will keep updating from time to time.

Advertisements