Developing Chat Bot using node.js on Windows 10 with Microsoft Bot Framework

Here we will setup the BOT builder SDK for node.js on Windows 10.

Requirements:

Step 1: Create a folder

C:\Users\SARTHAK\Desktop\BOT

Step 2: Open command prompt with folder path.

Step 3: Create package.json file using npm.init

C:\Users\SARTHAK\Desktop\BOT>npm init

Enter the project details as shown below:

bot1

Step 4: Install Microsoft Bot Builder SDK package

npm install –save botbuilder

Step 5: Install restify

npm install –save restify

Restify is the Node.js web service framework.

Step 6: Download and Install BotFramework-Emulator

bot2

Install the .exe file,

Screenshot (52)

Step 7: Create an app.js file in your folder

Add the following code:

</div>
<div>var restify = require('restify');</div>
<div>var builder = require('botbuilder');</div>
<div>var server = restify.createServer();</div>
<div>server.listen(process.env.port || process.env.PORT || 3978, function () {</div>
<div>console.log('%s listening to %s', server.name, server.url);</div>
<div>});</div>
<div>var connector = new builder.ChatConnector({</div>
<div>appId:process.env.MICROSOFT_APP_ID,</div>
<div>appPassword:process.env.MICROSOFT_APP_PASSWORD</div>
<div>});</div>
<div>server.post('/api/messages', connector.listen());</div>
<div>var bot = new builder.UniversalBot(connector, function (session) {</div>
<div>session.send("You said: %s", session.message.text);</div>
<div>});</div>
<div>

Your setup should look like below:

bot4

Step 8: Run your app.js file

node app.js

Step 9: Open the BotFramework-Emulator and enter the default endpoint url that your BOT listens to.

(Ignore the Microsoft App ID and Password if you don’t have one)

http://localhost:3978/api/messages

Like shown in the image below, say hi

bot3

Voila!

Your Microsoft BOT Builder SDK is ready setup on local Windows 10 machine is ready.

Read official docs from Microsoft here: Bot Service Documentation

For Getting Started with BOTs on Azure Check other blogs here:

Advertisement

One thought on “Developing Chat Bot using node.js on Windows 10 with Microsoft Bot Framework

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s