Created
November 17, 2017 15:47
-
-
Save lornajane/11a6ab01e65111819cae44c2baec5d73 to your computer and use it in GitHub Desktop.
Send a webhook from serverless js on openwhisk
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
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