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, 6:08 AM
Sir can you share the source code , in my case chat bot is showing in .net core not in bot application
Sidharth MahapatraPosted Jun 27, 2018, 1:51 AM
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, 11:30 AM
The bot is remote, but the service URL is localhost. Without tunneling software you will not receive replies.
Bhabani PrasadPosted Jun 9, 2018, 11:19 AM
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, 11:15 AM
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, 6:24 AM
Can i use my bot application into a console or other windows form application ?
vishal goyalPosted Feb 15, 2018, 4:06 AM
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, 8:56 AM
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, 7:15 AM
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, 2:04 PM
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, 12:23 PM
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, 9:27 AM
How to consume this bot service in UI?
Mahesh KalalPosted Apr 21, 2017, 6:26 AM
Hi sourabh, can u post a blog on integrating LUIS with c# web application.
a yoshithaPosted Mar 10, 2017, 7:29 AM
Very Informative article
Vuthy TepPosted Feb 2, 2017, 2:45 AM
Anyone has article on developing bot on Mobile App?
Krishna KPosted Jan 27, 2017, 2:49 AM
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 24, 2016, 1:13 AM
Nice one...
Thiruppathi RPosted Jun 15, 2016, 1:32 AM
Nice article..
Ashish SayalPosted Jun 5, 2016, 1:04 PM
How can we use this in my existing mobile app?
Prasanna MuraliPosted May 20, 2016, 10:46 AM
Nice one...
Bhuvanesh MohankumarPosted May 3, 2016, 12:46 PM
Good one..
Debasis SahaPosted Apr 15, 2016, 12:31 AM
Nice article..
Mahesh ChandPosted Apr 14, 2016, 11:11 AM
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 NagarajPosted Apr 14, 2016, 9:15 AM
Nice Sharing..
Vignesh ManiPosted Apr 14, 2016, 8:07 AM
Nice
Rahul Kumar SaxenaPosted Apr 14, 2016, 6:22 AM
Good Show Sourabh
Gowtham RajamanickamPosted Apr 14, 2016, 6:05 AM
nice article..
Puneet SinghPosted Apr 14, 2016, 4:25 AM
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 14, 2016, 3:54 AM
I am linking the mmicrosoft bot framework but it show malformed data error while testing the connection
Munesh SharmaPosted Apr 14, 2016, 2:33 AM
nice one article Sourabh , it will be helpful for beginners