Chat bot in Office 365

The article provides the foundation of design, implementation and hosting a chat bot in Azure framework and integrating it with any office 365 site / website where it can be used to meet various user requirements.

Introduction to Chat bot in Office 365:

Chat bots are the new virtual assistants for end users, which is a computer program driven by intelligent rules. Chat bots are programmed to simulate human conversation. They are smart to understand the natural language and translate them to application tasks. They can be used to automate and handle simple and repetitive tasks without human intervention.

SharePoint online: Ultimate tutorial guide PDF download

Chat bots have evolved over time and play important roles in Sales & Marketing – helping shopping a less time consuming experience, Finance – providing information about shares, information about bank services and plan budgets, News – showing news articles based on reader’s preferences based on questions asked, and Medicine – help track patients medication, remind on diets.

In this article, we will look at how we can develop a chat bot using Microsoft frame work for bots, make it friendly and intelligent to have a conversation with end users by building dialogs, host it / deploy it and access the bot at various application to automate end user tasks.

Finally, a chat bot is only smart as the developer who created it.

chat bot framework

chat bot framework

Bot Service: Bot Service provides an integrated environment that is purpose-built for bot development, enabling you to build, connect, test, deploy, and manage intelligent bots, all from one place. Bot Service leverages the Bot Builder SDK with support for .NET and Node.js.

Key Features of Bot Service:

Bot templates:

Bot Service templates allow you to quickly create a bot with the code and features you need.

Bring your own dependencies:

Bots support NuGet and NPM, so you can use your favorite packages in your bot.

Flexible development:

Code your bot right in the Azure portal or set up continuous integration and deploy your bot through GitHub, Visual Studio Team Services, and other supported development tools. You can also publish from Visual Studio.

Connect to channels:

Bot Service supports several popular channels for connecting your bots and the people that use them. Users can start conversations with your bot on any channel that you’ve configured your bot to work with, including Skype, Facebook, Teams, Slack, SMS, and several others.

Tools and services:

Test your bot with the Bot Framework Emulator and preview your bot on different channels with the Channel Inspector.

Bot Service includes five templates to help you get started with building bots. These templates provide a fully functional bot out of the box to help you get started quickly.

– Basic bot: can handle simple conversations.
– Form bot: conversations with forms through bot can collect input.
– Language understanding bot: uses natural language models (LUIS) to understand the user intent.
– Question and Answer bot: leverages the QnA Maker service to parse questions and provide answers
– Proactive bot: bot that can send proactive messages based on the Chat bot development framework

Chat bot development framework Development:

A bot can be developed online in Azure portal or offline using .NET SDK or Node.js SDK. The below steps describes how we can go about developing a bot using different resources.

Azure Portal : Bot Service:

The below points outlines the steps for creating and developing a bot online using Azure portal services.

1. Click the New button found on the upper left-hand corner of the Azure portal, then select AI + Cognitive Services > Web App bot.
2. A new blade will open with information about the Web App Bot. Click the Create button to start the bot creation process.
3. In the Bot Service blade, provide the requested information about your bot as specified in the table below the image.

microsoft bot framework tutorial.png

microsoft bot framework tutorial.png

4. Click Create to create the service and deploy the bot to the cloud.
5. Now that your bot is created, test it in Web Chat.


Bot can be developed using .NET SDK using the following steps.
1. Download the Bot Application, Bot Controller, and Bot Dialog .zip files.
2. Install the project template by copying Bot to your Visual Studio project templates directory.
3. Install the item templates by copying Bot and Bot to your Visual Studio item templates directory.
4. Open Visual Studio and create a new C# project. Choose the Bot Application template for your new project.

microsoft bot framework demo.png

microsoft bot framework demo.png

5. Code – Important Files
MessagesController.cs : receives the user message and invokes the RootDialog.
RootDialog.cs : Processes the message and generates a response. Dialogs are used to manage conversation flow with end user.
samples available at –
6. Start your bot in Visual Studio by using a browser as the application host.

microsoft bot framework.png

microsoft bot framework.png

chat bot framework tutorial.png

chat bot framework tutorial.png

Node.js SDK:

1. Install Node.js.
2. Create a folder for your bot.
3. From a command prompt or terminal, navigate to the folder you just created.
4. Run the following npm command: npm init
Based on the input provided, npm will create a package.json file that contains the information you provided.
5. In the folder that you created earlier for your bot, create a new file named app.js.
6. Save the following code in app.js

var builder = require(‘botbuilder’);
var connector = new builder.ConsoleConnector().listen();
var bot = new builder.UniversalBot(connector, function (session) {
session.send(“You said: %s”, session.message.text);

7. Navigate to your bot’s directory in a console window and start your bot: node app.js
the bot is now running locally and will respond to your messages.
8. Install Restify to create an API endpoint : npm install –save restify
9. Change the app.js as follows

var restify = require(‘restify’);
var builder = require(‘botbuilder’);

// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log(‘%s listening to %s’,, server.url);

// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword

// Listen for messages from users‘/api/messages’, connector.listen());

// Receive messages from the user and respond by echoing each message back (prefixed with ‘You said:’)
var bot = new builder.UniversalBot(connector, function (session) {
session.send(“You said: %s”, session.message.text);

Detail steps for Node.js is available at

Deploying chat bot:

Register bot and Host remotely with Bot Service.
1. Click the New button found on the upper left-hand corner of the Azure portal, then select AI + Cognitive Services > Bot Channels Registration.
2. A new blade will open with information about the Bot Channels Registration. Click the Create button to start the creation process.
3. In the Bot Service blade, provide the requested information about your bot as specified in the table below the image.

deploy bot service azure.png

deploy bot service azure.png

4. Click Create to create the service and register your bot’s messaging end point.

Host bot in Azure portal with continuous deployment:

After creating the bot successfully in Azure portal, the code can be downloaded offline and configured for continuous deployment. Creation of bot in Azure portal is mentioned earlier under Development.

The bot source code can be edited in the online editor.

1. Under the BOT MANAGEMENT section, Click Build.
2. Click Open online code editor. This will open the bot’s code in a new browser window.

hosting bot service azure.png

hosting bot service azure.png

Otherwise, the code can be downloaded and setup for continuous deployment.
1. In the Azure portal and open the blade for the bot.
2. Under the BOT MANAGEMENT section, Click Build.
3. Click Download zip file.

chatbot demo azure

chatbot demo azure

4. The downloaded code can be modified offline, tested with Bot Emulator framework. The updated code can be uploaded / deployed by configuring continuous deployment.

Note: Online editing of code will not work after continuous deployment is configured.

Continuous Deployment:

1. From your bot’s Build blade, click Configure continuous deployment.
2. Click Setup.

azure bot service examples

azure bot service examples

3. Click Choose source and choose Visual Studio Team Services.

chatbot demo office 365

chatbot demo office 365

4. Click Choose your account and choose an account.
5. Click Choose a project and choose a project.
6. Click Choose Branch and choose a branch to branch.
7. Click OK to complete the setup process.

chatbot demo

chatbot demo

Connect and Debug chat bot:

In Azure portal, after navigating to the Chat bot screen, there is an option available, shown as “Test in Web Chat”. This will open another window in which we can send/post chat messages and test how the bot responds.

chat bot

chat bot

Bot emulator framework is a desktop application helping to test and debug bots, either locally or remotely. The emulator provides additional details using which we can inspect the messages that the bot sends and receives. Note: The bot emulator framework requires ngrok to be installed and configured.

microsoft bot framework example

microsoft bot framework example

Debugging bots developed using C#:

Bots developed and hosted locally in IIS can be debugged using Visual studio and Bot emulator framework. Below are the steps.
1) Install Bot emulator framework and ngrok
2) Build and execute the code in debug mode from Visual studio.
3) Use break points at relevant locations.
4) Post your messages and observe the data exchanged in JSON format in bot emulator.

Bots developed and hosted remotely in Azure portal would require remote debugging. Below steps will help in remote debugging
1) Download and install Azure SDK.
2) Download and install Bot emulator framework and ngrok
3) Ensure that the code deployed is in “Debug” mode.
4) Ensure that remote debugging is enabled from Bot Service.
5) Go to server explorer, navigate to your bot and right click on it and “Attach Debugger”.
6) Post your messages and observe the data exchanged in JSON format in bot emulator.

Embed the Chat bot:

The bot can be configured for multiple channels. Below are two channels which can be used easily to embed a bot in a web application

Web chat bot – Iframe element

<iframe src=””></iframe>

The above line of code can be included in the web application as an iframe element.
Direct Line
<!DOCTYPE html>
<link href=”” rel=”stylesheet” />
<div id=”bot”/>
<script src=””></script>
directLine: { secret: direct_line_secret },
user: { id: ‘userid’ },
bot: { id: ‘botid’ },
resize: ‘detect’
}, document.getElementById(“bot”));

Hope this article will be helpful.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)


Sriram S

Experienced SharePoint Consultant with a demonstrated history of providing class leading and innovative solutions in various business domains. Skilled in Angular framework, SQL Server Reporting Services (SSRS), Agile Methodologies. Strong administrative professional with a Master of Science - MS focused in Management Science from University at Buffalo School of Management, The State University of New York and Executive MBA degree from Amrita School of Business.