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:
- Start with Node.JS command prompt, as shown below:
- Install Bot Builder
On Node command prompt, the command to be run is shown below:
- After successful installation, you will see the message on command prompt, as shown below:
With this, you are set to use Bot builder SDK in Node.js.
Build a Bot
- Create a folder named bots on your file system.
- Create a file botserver.js, using the code given below under bots folder.
- var builder = require('botbuilder');
- var connector = new builder.ConsoleConnector().listen();
- var bot = new builder.UniversalBot(connector);
- bot.dialog('/', function(session)
- {
- session.send("Hi there, How can I help you?");
- });
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:
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:
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.