Microsoft Bot Framework And Node.JS - Part One

Microsoft Bot Framework

Microsoft Bot Framework can help us in developing the chat bots, that can be integrated with platforms such as Skype, Slack, Telegram, Email and the Web.

How I see this framework is the human language power with the computing and intelligence powers, combined together to provide a great conversation experience.

This framework has the following three components,

  • Bot Builder Software Development Kit
  • Developer Portal
  • Bot Directory

In this article, we will actually build one of the chat bots, using the very first components of this framework -- Bot Builder SDK.

Bot Builder for Node.js

The Bot Builder SDK is an open source SDK, hosted on GitHub, that provides everything you need to build great dialogs within your Node.js, .NET or REST API-based bot Application.

Since I have been playing with Node.js these days, this article will use Node.js for our chatbot Application. Make sure you already have Node.js installed on your machine.

Installing Bot builder for Node.js

Now, let's follow the steps, given below, to get started with Bot Builder and Node.js for our very basic chat Bot, given below:

  1. Start with Node.JS command prompt, as shown below:

    Node.JS command prompt

  2. Install Bot Builder
    On Node command prompt, the command to be run is shown below:

    command

  3. After successful installation, you will see the message on command prompt, as shown below:

    command

    With this, you are set to use Bot builder SDK in Node.js.

Build a Bot

  1. Create a folder named bots on your file system.
  2. Create a file botserver.js, using the code given below under bots folder.
    1. var builder = require('botbuilder');  
    2. var connector = new builder.ConsoleConnector().listen();  
    3. var bot = new builder.UniversalBot(connector);  
    4. bot.dialog('/', function(session)  
    5. {  
    6.     session.send("Hi there, How can I help you?");  
    7. });  

In the code, given above, require() loads ‘botbuilder’ module.

Since we are using command line to interact with this Bot, we are using ConsoleConnector here.

UniversalBot class implements all the logic to manage Bot conversations from our command line channel. For these Bot conversations, Bot object uses the dialog component.

Running a Bot

Open a new Node.js command prompt and navigate to our bots folder using command cd and run the command, given below:

command

Our botserver.js has run successfully and our conversation has begun with our Bot through this command line channel.

Just type ‘Hi’ on the command prompt to see how Bot reacts to it, as shown below:

command

Thus, Bot is replying to us, based on the input we are providing from the command line.

In our next article, we will see some more interactivity with our Bot.

Next Recommended Readings