You are here

How to Use the Microsoft Bot Builder SDK to Build a Bot

The benefits of having a bot in a business include automation, user interaction, facilitation of repetitive conversations, lead generation, and reduction of costs in the long term.

In the Microsoft tutorial Create a bot with the Bot builder SDK for Node.js, contributors Kim Brandl, Robert Standefer, John Dempsey, and Den Delimarsky share the steps for building a bot with the SDK and testing it with the Framework Emulator.

Initially, you will need to install Node.js, create a folder for your bot, form a command prompt, and run the npm command nodejs npm init.

To create your bot, create a new file named app.js, then open that file in an open a text editor to include the following code below. It will allow the bot to send and receive messages, echoing back user input:

var restify = require('restify');
var builder = require('botbuilder');

// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
   console.log('%s listening to %s', server.name, server.url); 
});

// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});

// Listen for messages from users 
server.post('/api/messages', connector.listen());

// Receive messages from the user and respond by echoing each message back (prefixed with 'You said:')
var bot = new builder.UniversalBot(connector, function (session) {
    session.send("You said: %s", session.message.text);
});

After you save the file, you will be ready to run and test yout bot. If your bot responds to your messages, then you know you’ve succeeded. The bot can be used for sending and receiving messages, handling user actions, recognizing user intent, sending a rich card, sending attachments, and saving user data. Bots are often used strongly in shopping, payments, food delivery services, healthcare, and customer support applications.

Original Article

Mayela Gonzalez Mayela Gonzalez is a Web Content Editor at ProgrammableWeb.com
 

Comments