-
-
Save NikhilBansal21/c35b2dfb0dc69084fdbaca09c1ed77f1 to your computer and use it in GitHub Desktop.
node js code for chat bot using azure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var restify = require('restify'); | |
var builder = require('botbuilder'); | |
var http = require('http'); | |
var Request = require("request"); | |
// 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); | |
}); | |
// chat connector for communicating with the Bot Framework Service | |
var connector = new builder.ChatConnector({ | |
appId: 'Your Azure projects app id', | |
appPassword: 'Your Azure projects 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) { | |
var text=session.message.text; | |
var res = encodeURI(text); | |
console.log("id>>>>>"+res); | |
var chunkObj,str; | |
var res = encodeURI(text); | |
console.log('input text>>>>'+res); | |
var options = { | |
host: 'localhost', | |
port:'5005', | |
path: '/conversations/default35/respond?token=your-auth-token&query='+res | |
}; | |
http.get(options, function(resp){ | |
resp.body = ""; | |
resp.on('data', function(chunk){ | |
//do something with chunk | |
resp.body += chunk; | |
chunkObj = JSON.parse(resp.body); | |
console.log(">>>>>>>>>>>>>>>>>>>>>>"+resp.body); | |
}).on("end",function(){ | |
chunkObj = JSON.parse(resp.body); | |
console.log("this>>>>"+chunkObj[0].text); | |
for(var i=0;i<chunkObj.length;i++){ | |
session.send(chunkObj[i].text); | |
} | |
}).on("error", function(e){ | |
console.log("Got error: " + e.message); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment