Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Send a webhook from serverless js on openwhisk
function main(data) {
return new Promise(function(resolve, reject) {
var request = require('request');
if(data.status == 'new') {
var message = "New question: <" + data.question.link + "|" + data.question.title + "> (tagged: " + data.question.tags + ")";
var options = {
"text": message,
"icon_emoji": ":postit:"
};
request({
url: data.slackURL,
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(options)
}, function (err, response, body) {
if(err) {
console.log(err);
reject ({payload: "Failed"});
} else {
console.log("Status: " + response.statusCode);
console.log("Response Body: " + body);
resolve( {payload: "Notified"} );
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment