Introduction
What is Microsoft BOT Framework
How to build your own simple Bot Application: The following steps will explain to you how to build your own simple Bot Application using Microsoft Bot Framework.
Step 1: Firstly, you have to install some prerequisite software,
- Visual Studio 2015 Update 1.
- Also Update your all Visual Studio extensions through tools > Extensions and Updates > Updates.
Step 2: Download the Bot Application Template from the following link: Bot Application Template.
Step 3:
The above link will download a ZIP File, just save that ZIP file in “%USERPROFILE%\Documents\Visual Studio 2015\Templates\ProjectTemplates\Visual C#".
Step 4: Now open your Visual Studio.
Step 5: Now create a new Bot project in Visual Studio. To create a new Bot Project, here are the steps:
- First of all go to File, New, then Project or press CTRL +SHIFT + N.
- Now one dialog box will open. From that select Visual C# Project and you will find an option Bot Application, choose that and give the name of the project.

Step 6: After creating a project, you will get some files in solution explorer as you can see in the following figure.

Step 7:
Open Web.Config File, and give the AppId and AppSecret keys for your project. If you are running this project locally, then you can give any AppId and AppSecret. Here's the figure,


Note:
For the local system, you can provide AppID and AppSecret. But if you host your bot somewhere then you have to register your bot here. And after registration, you will get your bot AppID and AppSecret.
Step 8: If you see your web.config then you will get the default document file that will run when your application will run.

Step 9: If you run your project then the output will look like the following:

The above output is nothing but your default document code that is written in "default.htm" File.
Step 10: Now if you expand your Controllers folder you will get only one Controller File that is "MessagesController", so open MessagesController.


When you open MessagesController, the following code is written by default:
- using System;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Threading.Tasks;
- using System.Web.Http;
- using System.Web.Http.Description;
- using Microsoft.Bot.Connector;
- using Microsoft.Bot.Connector.Utilities;
- using Newtonsoft.Json;
- namespace MySimpleBotApp
- {
- [BotAuthentication]
- public class MessagesController : ApiController
- {
- /// <summary>
- /// POST: api/Messages
- /// Receive a message from a user and reply to it
- /// </summary>
- public async Task<Message> Post([FromBody]Message message)
- {
- if (message.Type == "Message")
- {
- // calculate something for us to return
- int length = (message.Text ?? string.Empty).Length;
- // return our reply to the user
- return message.CreateReplyMessage($"You sent {length} characters");
- }
- else
- {
- return HandleSystemMessage(message);
- }
- }
- private Message HandleSystemMessage(Message message)
- {
- if (message.Type == "Ping")
- {
- Message reply = message.CreateReplyMessage();
- reply.Type = "Ping";
- return reply;
- }
- else if (message.Type == "DeleteUserData")
- {
- // Implement user deletion here
- // If we handle user deletion, return a real message
- }
- else if (message.Type == "BotAddedToConversation")
- {
- }
- else if (message.Type == "BotRemovedFromConversation")
- {
- }
- else if (message.Type == "UserAddedToConversation")
- {
- }
- else if (message.Type == "UserRemovedFromConversation")
- {
- }
- else if (message.Type == "EndOfConversation")
- {
- }
- return null;
- }
- }
- }

Step 12:
And you can see there is one more Action Method that is HandleSystemMessage, where I am changing in BotAddedToConversation condition. Changes are as follows:

Step 11: When you will run your application again the same default page will open. So once again run your application.

Step 12:
Now to emulate your application you have to open the Bot Framework Emulator. You can download Bot Framework Emulator from the following link.

Step 13: After providing AppId And AppSecret, you can Send Request for Bot Added To Conversation.
After sending the request of Bot Added To Conversation Our Message will return which we have written for BotAddedToConversation in HandleSystemMessage action.
Step 14 :

Step 15: Now send a message, so post action will call and whatever you are returning from Post Action you have written what will show.

After Sending the message

Read more articles on Machine Learning:


ishwar giriPosted Feb 3, 2021, 1:08 AM EST
Sir can you share the source code , in my case chat bot is showing in .net core not in bot application
Sidharth MahapatraPosted Jun 26, 2018, 9:51 PM EDT
I'm trying to modify code as message.Type. I get a compile time error as Message does not have a definition for Type.
Bhabani PrasadPosted Jun 9, 2018, 7:30 AM EDT
The bot is remote, but the service URL is localhost. Without tunneling software you will not receive replies.
Bhabani PrasadPosted Jun 9, 2018, 7:19 AM EDT
This site can’t be reachedyour_bots_hostname’s server IP address could not be found.. got this error even setting a demo MicrosoftAppId and MicrosoftAppPassword
Bhabani PrasadPosted Jun 9, 2018, 7:15 AM EDT
After downloading what step should be follow. its not clearly described. can you tell me i am stuck after downloading bot Emulator zip file
mohit kPosted May 26, 2018, 2:24 AM EDT
Can i use my bot application into a console or other windows form application ?
vishal goyalPosted Feb 14, 2018, 11:06 PM EST
Hi Sourabh,I have created chatbot demo application from your articl. Now I just want to integrate this chat bot to my existing asp.net web application, for this I have created a sample asp.net website and hosted locally on IIS can anyone please tell how should I publish bot application locally and on IIS and integrate this to my demo asp.net web application?
सचिन चौहानPosted Sep 18, 2017, 4:56 AM EDT
Hi Sourabh, please let me know if using VS 2015 is absolute compulsory for working on Box framework. Can we do the same in VS 2013?
Rahul VermaPosted Aug 27, 2017, 3:15 AM EDT
Thank You for the wonderfull article. I followed the above steps but my default.htm file has only 13 lines in it and no code like yours and I am not able to run the code plz HELP.
Pavan KumarPosted Jul 30, 2017, 10:04 AM EDT
How can we add different dialogs in the bot. Is it possible to return c# defined objects like a web page or a view from bot to user
Somesh DhalPosted Jun 9, 2017, 8:23 AM EDT
Where is the bot service hosted?I mean if I want to start an application in the client's machine with some command can I do that with Microsoft bot framework?
sanyam kulshresthaPosted May 2, 2017, 5:27 AM EDT
How to consume this bot service in UI?
Mahesh KalalPosted Apr 21, 2017, 2:26 AM EDT
Hi sourabh, can u post a blog on integrating LUIS with c# web application.
a yoshithaPosted Mar 10, 2017, 2:29 AM EST
Very Informative article
Vuthy TepPosted Feb 1, 2017, 9:45 PM EST
Anyone has article on developing bot on Mobile App?
Krishna KPosted Jan 26, 2017, 9:49 PM EST
How to display buttons in response. I want to display "Yes" and "No" buttons after display response like Are you happy with the my answer? "Yes" "No" if user clicks on Yes it should display on chat window.
Prasanna MuraliPosted Jun 23, 2016, 9:13 PM EDT
Nice one...
Thiruppathi RPosted Jun 14, 2016, 9:32 PM EDT
Nice article..
Ashish SayalPosted Jun 5, 2016, 9:04 AM EDT
How can we use this in my existing mobile app?
Prasanna MuraliPosted May 20, 2016, 6:46 AM EDT
Nice one...
Bhuvanesh MohankumarPosted May 3, 2016, 8:46 AM EDT
Good one..
Debasis SahaTOP 100Posted Apr 14, 2016, 8:31 PM EDT
Nice article..
Mahesh ChandTOP 10Posted Apr 14, 2016, 7:11 AM EDT
Nice to see work on Bot Framework. Bots seems to be the next big thing to build Intelligent software. Google has bots and Facebook just open sourced its bot framework.
Kuppurasu NagarajTOP 100Posted Apr 14, 2016, 5:15 AM EDT
Nice Sharing..
Vignesh ManiTOP 100Posted Apr 14, 2016, 4:07 AM EDT
Nice
Rahul Kumar SaxenaTOP 100Posted Apr 14, 2016, 2:22 AM EDT
Good Show Sourabh
Gowtham RajamanickamTOP 100Posted Apr 14, 2016, 2:05 AM EDT
nice article..
Puneet SinghPosted Apr 14, 2016, 12:25 AM EDT
on bot framework dashboard on left handside there is an option to test your connection to bot. I linked to telegram app but when I test it shows malformed data error in json https://dev.botframework.com/
Puneet SinghPosted Apr 13, 2016, 11:54 PM EDT
I am linking the mmicrosoft bot framework but it show malformed data error while testing the connection
Munesh SharmaPosted Apr 13, 2016, 10:33 PM EDT
nice one article Sourabh , it will be helpful for beginners