Posted in Chatbots, Dynamics 365

Part 2 – Bot Framework

The recently released Bot Framework equips us with the basic plumbing that is required for chat sessions and making connections with services like LUIS. Some of the key features of Bot Builder SDK include

· Support for both C# and Node.js

· Open source on Github

· Conversation support – Prompts, Dialog and Rulesets for form flows

· Chat emulator – a client for testing

· Connector to Cognitive services like LUIS

Once you have the prerequisites discussed in the previous part, you can create a new bot project from Visual Studio by going

File > New > Project > Bot Application

The project setup is based on WebAPI / MVC style routing and you need to implement a message controller. Below is a screenshot of the source code for the bot


Handling messages

The main entry point of the bot framework is the MessagesController as shown below

public class MessagesController : ApiController
public virtual async Task<HttpResponseMessage> Post([FromBody] Activity
// check if activity is of type message
if (activity != null && activity.GetActivityType() ==
await Conversation.SendAsync(activity, () => new InsuranceDialog());
return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);

The controller is secured by the BotAuthentication decoration that secures the bot’s endpoint, then we are checking the incoming message to ensure it is of type message and initiate a dialog called InsuranceDialog. The dialog then passes the message to LUIS to determine the customer’s intent and generates a reply accordingly. We will dig in more details of LUIS in the next blog.


Replies from the bots are posted back on the chat screen using some of the common methods described below

context.PostAsync("Hi there. Welcome to BestPrice.");

Above line shows how to post a basic message back to the user

ResumeTypeOptionsAsync, options, "Let us know what are you interested in?");

Here we are using a dialog class which not only posts a message with options but also listens to the user’s input i.e. the option they chose.

PromptDialog.Confirm(context, HandleInsuranceOptions,"Do you want to know about 
our insurance?"
,"Didn't get that!");

This is an example of a confirm message where we expect a Yes or No from the user

Using the Channel Emulator

One of most useful application for such projects is the Channel Framework Emulator which is a client you use to unit test your bots. It can connect to both online and locally deployed bot apps. You need to ensure that AppId and Secret you use in this app are the ones your bot app uses i.e. the ones in its web.config. Below is a screenshot of our bot being tested locally. Let us meet in the next blog post where we explore LUIS.


Posted in Chatbots, Dynamics 365

Build a Chatbot for Dynamics CRM– Part 1

“Chatbots are about taking the power of human language and applying it more pervasively to our computing.”

Satya Nadella

We have seen an age of mobile phone apps, and guess what is coming next? Chatbots. To acknowledge their soaring growth and to leverage on this business opportunity, at this year’s Build conference, Microsoft has released a full framework to build bots. It is called the Bot Framework.

Microsoft is not alone in the game, Facebook and Amazon have released their bot platforms as well, and the developer base is growing at an astonishing pace. Technology is making huge leaps in Natural Language Processing, with Google just having open-sourced their NLP parser and Microsoft having enriched their Language platform LUIS (Language Understanding Intelligent Service). These advancements coupled with the capability to build chatbots presents an incredible opportunity for developers and the businesses alike. A proof of their popularity is this statistic that says since last year bots have outnumbered humans on the internet. So not only they are a raging trend but also a hot market.

But what does all this mean for businesses? Put simply, organisations will be able to leverage Conversation as a platform where they can deploy intelligent chatbots to serve their customers. The equation of return on investment is quite attractive too based on a survey finding that the average cost of a customer transaction via phone is around $2.50 and, the average cost of a digital transaction (online or on mobile) is only around $0.17.  It is not all doom and gloom though, there will still be lot of human element required to fill up what bots lack, at least for the foreseeable future.

I decided to give the Microsoft’s bot platforms a whirl to check how easy it is to build a basic chat-bot. Through this blog series, I will walk you through the process of building a chat-bot that may interact with Dynamics CRM and can optionally be deployed using Microsoft portals. We will use two spanking new platforms released recently as a part of Microsoft’s Cognitive Suite: Bot Framework and LUIS. Before we start building, let us first understand how bots fit into the ecosystem.


We will use the setup outlined in the above diagram. The bot will be primarily built on the Bot Framework using .NET (Node.js is also supported) and it will interact with LUIS to parse the natural language and try to understand what the customer means.

There will be three more parts to this series and I will also link the source code of the working bot in the last part

Part 1 – Introduction

Part 2 – Bot Framework

Part 3- LUIS

Part 4 – Chatbot Integration and Deployment

Let us layout the scenario to understand what we are building.


Say we are an insurance company called BestPrice and we are deploying a chatbot that customers can converse with to know about our products and to register their interest. The bot will pass some of the conversations to LUIS to determine customer’s intent. Three intents will be used for this demo

Greeting – Conversation is just a greeting like hi, hello, etc.

Enquire – The customer wants to enquire about our insurance products

Engage – Customers wants us to engage with them


In order to setup the project you need to have the following prerequisites

1. Bot Framework VS template

2. Bot Framework Channel Emulator

3. Bot Framework dlls (via Nuget)

4. A developer account with Bot Framework

5. A developer account with LUIS with subscription key

6. Once the bot is deployed online it needs to be registered with bot framework

You can read more about the above prerequisites here or search them online

In the next instalment we will start building the bot and go through some of key building blocks.