Last active
May 22, 2018 09:40
-
-
Save zilahir/5fcf81186cfc5acb099c5590721a3b92 to your computer and use it in GitHub Desktop.
send message to slack using firebase cloud function
This file contains hidden or 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
const functions = require('firebase-functions'); | |
const request = require('request'); | |
exports.addMessageToSlack = functions.https.onRequest((req, resp) => { | |
return new Promise((resolve, reject) => { | |
const message = array['message']; | |
request.post( | |
"https://hooks.slack.com/X/Y/Z", | |
{ json: { text: `You have a new message: ${message}`} } | |
) | |
.on('response', function(response) { | |
if(response.statusCode === 200) { | |
resp.send(JSON.stringify('success')); | |
resolve(); | |
} else { | |
reject(response); | |
} | |
}) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment