javascript - Microsoft Bot Framework - how to send responses from a 3rd party API -


using microsoft bot framework, how can proxy api between incoming , outgoing bot messages?

i've replaced:

server.post('/api/messages', connector.listen()); 

with own implementation takes req.body.text , sends separate endpoint.

how can send endpoints response chat?

server.post('/api/messages', (req, res, next) => {   request.post('endpoint', {     json: {"text": req.body.text},   }, (error, response, body) => {     // how send body outgoing chat message?   }) }) 

update:

to point out why ezequiel jadib's answer won't work, i've added complete code. req not defined within bot's callback function.

const restify = require('restify') const builder = require('botbuilder') const request = require('request')  // setup restify server const server = restify.createserver() server.use(restify.plugins.bodyparser()) server.listen(process.env.port || process.env.port || 3978, function () {    console.log('%s listening %s', server.name, server.url)  })  // create chat connector communicating bot framework service const connector = new builder.chatconnector({     appid: process.env.microsoft_app_id,     apppassword: process.env.microsoft_app_password })  server.post('/api/messages', connector.listen())  const bot = new builder.universalbot(connector, function (session) {   request.post('endpoint', {     json: {"text": req.body.text}   }, (error, response, body) => {     session.send(body)   }) }) 

first, think should go through documentation node.js question seems related foundations of sdk.

then, think calling endpoint in wrong place. instead of doing on post, should in function of universalbot user messages received.

you can try like:

var bot = new builder.universalbot(connector, function (session) {     request.post('endpoint', {       json: {"text": session.message.text},     }, (error, response, body) => {         session.send("you said: %s", "your endpoint response");    }) }); 

Comments

Popular posts from this blog

Add new key value to json node in java -

javascript - Highcharts Synchronized charts with missing data points -

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -