Skip to content

Instantly share code, notes, and snippets.

@lornajane
Created November 17, 2017 15:47
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 lornajane/11a6ab01e65111819cae44c2baec5d73 to your computer and use it in GitHub Desktop.
Save lornajane/11a6ab01e65111819cae44c2baec5d73 to your computer and use it in GitHub Desktop.
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