SUSI AI Bots with Microsoft’s Bot Framework

The Bot Framework is used to build intelligent chatbots and it supports .NET, Node.js, and REST. To learn about building bots using bot framework go to  https://docs.microsoft.com/en-us/bot-framework/bot-builder-overview-getstarted . Now to build SUSI AI bot for different platforms like facebook, telegram, kik, skype follow below given steps. Install Node.js from the link below on your computer if you haven’t installed it already. https://nodejs.org/en/ Create a folder with any name and open a shell and change your current directory to the new folder you created. Type npm init in shell and enter details like name, version and entry point. Create a file with the same name that you wrote in entry point in above given step. i.e index.js and it should be in same folder you created. Type following commands in command line  npm install --save restify.After restify is installed type npm install --save botbuilder   after botbuilder is installed type npm install --save request when all the modules are installed check your package.json modules will be included within dependencies portion. Your package.json file should look like this. { "name": "skype-bot", "version": "1.0.0", "description": "SUSI AI Skype Bot", "main": "app.js", "scripts": {   "test": "echo \"Error: no test specified\" && exit 1",   "start": "node app.js" }, "author": "", "license": "ISC", "dependencies": {   "botbuilder": "^3.8.1",   "request": "^2.81.0",   "restify": "^4.3.0" } } Copy following code into file you created i.e index.js var restify = require('restify'); var builder = require('botbuilder'); var request = require('request'); // Setup Restify Server var server = restify.createServer(); server.listen(process.env.port || process.env.PORT || 8080, function() {    console.log('%s listening to %s', server.name, server.url); }); // Create chat bot var connector = new builder.ChatConnector({  appId: process.env.appId,  appPassword: process.env.appPassword }); var bot = new builder.UniversalBot(connector); server.post('/api/messages', connector.listen()); //When bot is added by user bot.on('contactRelationUpdate', function(message) {    if (message.action === 'add') {        var name = message.user ? message.user.name : null;        var reply = new builder.Message()            .address(message.address)            .text("Hello %s... Thanks for adding me. You can talk to SUSI now.", name || 'there');        bot.send(reply);    } }); //getting response from SUSI API upon receiving messages from User bot.dialog('/', function(session) {    var options = {        method: 'GET',        url: 'http://api.asksusi.com/susi/chat.json',        qs: {            timezoneOffset: '-330',            q: session.message.text        }    }; //sending request to SUSI API for response    request(options, function(error, response, body) {        if (error) throw new Error(error);        var ans = (JSON.parse(body)).answers[0].actions[0].expression;        //responding back to user        session.send(ans);    }) }); You have to replace appID and appPassword with your own ID and Password which you can get by below given steps. Sign in/Sign up to this https://dev.botframework.com/. After signing in go to My Bots option at the top of the page and Create/Register your bot. Enter details of your bot and click on “Create Microsoft App ID and password”.  Leave messaging endpoint for now after getting app ID and password we will write messaging endpoint. Copy your APP ID and Password and save them for later use. Paste your App ID in box given for ID on bot registration page. Now we have to create messaging endpoint to listen for requests. Make a github repository and push…

Continue ReadingSUSI AI Bots with Microsoft’s Bot Framework