Deploying A Simple Bot With Bot Builder SDK Using Visual Studio 2017

Introduction

In this article, I am going to show how to create and configure a bot using Visual Studio and also, how to run that bot using Bot Emulator in our local system. This article explains about building a bot by using the Bot Application template and the Bot Builder SDK for .NET and then testing it with the Bot Framework Emulator.

This article consists of three parts.

  • Building a Bot Using Bot Application Template
  • Working with the Bot Emulator
  • Testing our Bot.

Prerequisites

Follow these steps to Create a Bot Application

For creating Bot application using Visual Studio, you may need to download the Bot template from this link.

After downloading the Bot Template, extract that Zip file and move that to the desired file Location. In File Explorer, go to Documents --->Visual Studio 2017---> Templates ---> Project Templates ---> Visual C#. Now, paste the extracted file to the above-mentioned Directory.

Then, open the Visual Studio 2017, choose Visual C# under Templates and then search the Bot Framework. Give the desired name for your Bot application.

Bot Application

For our Bot application, we need some NuGet Packages that may be installed in the Solution Explorer by right-clicking on our project and choosing "Manage NuGet Packages". In the "Browse" tab, type "Microsoft.Bot.Builder". It shows the package. Just click on the Install or Update button to install that package.

NuGet Packages

Explore the file structure of your Bot application

The "Post" method within "Controllers\MessagesController.cs" receives messages from the user and that invokes the default message. The default dialog processes the message and generates a response.

Post

The "MessageReceivedasync" method within "Dialogs\RootDialog.cs" sends a reply that echoes back the user's message with the text the user has given to the Bot.

User

This gives the output like the Echo the user has given as input. Then, Run your application in any browser.

 Echo

Follow these steps to work with the Bot Emulator

  1. Download the Emulator and install it into your system.
  2. After the installation, open the Emulator.
    Bot Emulator

The Emulator is a desktop application that lets you test and debug the Bot on localhost or lets it run remotely through a tunnel. After installing the Emulator, start your bot in Visual Studio by using a browser that you use.

Browser

http://localhost:3979/api/messages

Copy the above link and paste it into your Bot Emulator, followed by pressing the "Connect" button. We won't need to specify a Microsoft App ID and Microsoft App password. You can leave these fields blank for now. Using the App ID and App Password allows working with other bots that we created using Azure Portal and the Bot Framework.

Microsoft App ID

Thus, our bot is working in the Emulator and the response message is also displayed. Our bot is running locally and is connected to the Emulator. Test your Bot by giving a few messages to the Emulator. You should see that the bot responds to each message you send by echoing back your message prefixed with the text we sent.

 Messages

Summary

I hope you have understood how to create the Bot framework using Visual Studio and also, how to run the Emulator for the Bot Framework in our system.


Similar Articles