Last active
March 14, 2017 17:44
-
-
Save sunnygleason/fd1239cec0cb1f904882d78c7fac8f22 to your computer and use it in GitHub Desktop.
PubNub Bot Integration BLOCK w/ Gupshup
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
// | |
// NOTE: In Gupshup, your bot should have code like this: | |
// | |
// function HttpEndpointHandler(context, event) { | |
// context.sendResponse("Hello there, the current time is: " + new Date().toISOString()); | |
// } | |
// | |
export default (request) => { | |
const xhr = require('xhr'); | |
const botname = 'YOUR_BOT_NAME'; | |
const message = JSON.stringify(request.message.text); | |
const url = "https://www.gupshup.io/developer/bot/" + botname + "/public"; | |
const http_options = { | |
"method": "POST", | |
"body": "message=" + message | |
}; | |
return xhr.fetch(url, http_options).then((response) => { | |
request.message.bot_reply = response.body; | |
return request; | |
}).catch((reason) => { | |
console.log(reason); | |
return request; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment