Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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