X
29May

Create a Basic Bot with the Bot Builder SDK for.NET

In this blog, I am going to show how to create a basic bot using Microsoft Bot Builder Framework and SDK for .NET.

What is a Bot?

A bot is a software that is designed to automate the tasks you would usually do on your own, like booking a flight ticket, adding an appointment to your calendar or fetching and displaying information.

Chat bots are computer programs that mimic conversation with people using artificial intelligence.

A bot may be as simple as basic pattern matching with a response, or it may be a sophisticated weaving of artificial intelligence techniques with complex conversational state tracking and integration to existing business services.

Let’ see how to create a Bot using Bot Builder SDK

The Bot Builder SDK for .NET is a framework for developing bots using visual studio and windows.

Prerequisites:

  • Install Visual Studio 2017 for windows
  • Install Bot Framework Emulator, which is the client you will use for testing your bot
  • Download the Bot Application Template and install the template by saving .zip file to your Visual studio 2017 project templates directory which is typically located here: %USERPROFILE%\Documents\Visual Studio 2017\Templates\ProjectTemplates\Visual C#\

 

  • After ensuring you have all the prerequisites ready, Open Visual Studio and create a new C# project by choosing Bot Application template.

       Create

 

By using Bot Application template, you are creating a project that already contains all the components that are required to build simple bot, including a reference to the Bot Builder SDK for .NET, included in the Microsoft.Bot.Builder NuGet Package.

 

  • Right click on your project's References folder in the Solution Explorer and click Manage NuGet packages
  • In the Updates tab, type Microsoft.Bot.Builder.
  • Locate the package in the list of search results, and click the Update button for that package.
  • Follow the prompts to accept the changes and update the package.

Open solution explorer and explore the Bot code.

First, the Post method within Controllers\MessagesController.cs receives the message from the user and invokes the root dialog.

Dialogs are used to model a conversation and manage conversation flow. Each dialog is an abstraction that encapsulates its own state in a C# class that implements IDialog.

MessageController

 

The root dialog processes the message and generates a response. The MessageReceivedAsync method within Dialogs\RootDialog.cs sends a reply that echoes back the user's message, prefixed with the text 'You sent' and ending in the text 'which was ## characters', where ## represents the number of characters in the user's message.

Dialogs help organize the logic in your bot and manage conversation flow. Dialogs are arranged in a stack, and the top dialog in the stack processes all incoming messages until it is closed or a different dialog is invoked.

RootDialog

Next, you need to test your Bot using the Bot framework emulator to see it in action.

The emulator is a desktop application that lets you test and debug your bot on localhost or running remotely through a tunnel. The emulator displays messages as they would appear in a web chat UI and logs JSON requests and responses as you exchange messages with your bot.

Click on the Run button, Visual Studio will build the application, deploy it to localhost, and launch the web browser to display the application's default.htm page as shown below:

browser

Open the botframework-emulator and connect your bot, Type http://localhost:3979/api/messages into the address bar. This is the default endpoint that your bot listens to when hosted locally.

Set the Locale as en-US and click Connect. Because you are running your bot locally, you won't need to specify Microsoft App ID and Microsoft App Password. You can leave these fields blank for now. You will get these two details when you register your bot in the Bot Framework Portal. 

connect

Click on the connect button and type hi, hello etc.

You may see that the bot responds to each message you send by echoing back your message prefixed with the text "You said" and ending in the text 'which was ## characters', where ## represents the number of characters in the user's message.

References:

  • https://docs.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-overview?view=azure-bot-service-3.0
  • https://dev.botframework.com/ 

 

Thank you..!!

Related

HOW TO DO BACKUP AND RESTORE ENTIRE K8S CLUSTER?

If you have deployed different applications on k8s cluster using various objects like deployments, p...

Read More >

Software Services

The whole world has come to realize the role played by Information Technology and looking at ways to...

Read More >

An introduction about Node.JS and usage of its modules

Node.js is an open source, cross platform JavaScript runtime environment for developing variety of t...

Read More >

Swift Mapping and Flat Mapping

In this blog post, I will introduce some of useful tips and techniques of using swift mapping and fl...

Read More >

How to Sync On-premise AD with Windows Azure AD using Azure AD Connect tool

 Azure AD is a service that provides identity and access management capabilities in the cloud. ...

Read More >

Introduction to KnockOut.Js in Asp.Net

What is KnockOut.Js?Knockout.Js (simply KO) is a powerful JavaScript library which allows developers...

Read More >

LDAP Integration with Sonatype Nexus

Sonatype Nexus supports the Repository Manager integration with various active directory systems for...

Read More >

Integration of Git into Visual Studio

Nearly all versions of the Visual Studio IDE provide integration features for source control. Git Cl...

Read More >

Assertions in Coded UI

Let us discuss how to add assertions in coded UI. Assertions are checkpoints/benchmarks to UI c...

Read More >

WCF SOAP and REST Services

WCF (Windows Communication Foundation) is a programming platform and runtime system for building, co...

Read More >

Share

Comments

HI, Your article is too good and informative. I am searching for Artificial Intelligence and I get exact article i am thankful to you for sharing this educational article .Keep writing and sharing educational article like this which can help us to grow our knowledge.
5/23/2020 5:29:13 PM | Reply

Post a Comment

  • Recent
  • Popular
  • Tag
  • The Ansible Architecture

    Ansible is an open source, IT automation tool. It can configure systems, deploy software, and orchestrate more advanced IT tasks such as continuous deployments or zero downtime rolling updates. In thi...
  • Subversion (Centralized Version Control System)

    Version control system is a repository of files, often the files for the source code of computer programs with monitored access. They are essential for any form of distributed, collaborative developme...
  • Volume management in Kubernetes

    Since pods created in k8s are ephemeral, we are able to get the data as long as pods are alive, but if pods are terminated data stored in it completely lost and it cannot be get back, for that we need...
  • LDAP Integration with Sonatype Nexus

    Sonatype Nexus supports the Repository Manager integration with various active directory systems for authentication, such as Microsoft Exchange / Active Directory, OpenLDAP, ApacheDS, and others. In o...
Monthly Archive
Subscribe
Name

Contact Us
  • *
  • *