Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Last active March 14, 2017 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnygleason/fd1239cec0cb1f904882d78c7fac8f22 to your computer and use it in GitHub Desktop.
Save sunnygleason/fd1239cec0cb1f904882d78c7fac8f22 to your computer and use it in GitHub Desktop.
PubNub Bot Integration BLOCK w/ Gupshup
//
// 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