Here we will setup the BOT builder SDK for node.js on Windows 10.
Requirements:
- Install node.js
- Visual Studio Code Editor or any code editor like Nodepad++
- Microsoft Bot Emulator
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:
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
Install the .exe file,
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:
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)
Like shown in the image below, say “hi“
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:
One thought on “Developing Chat Bot using node.js on Windows 10 with Microsoft Bot Framework”