Skip to content

Instantly share code, notes, and snippets.

@zilahir
Last active May 22, 2018 09:40
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 zilahir/5fcf81186cfc5acb099c5590721a3b92 to your computer and use it in GitHub Desktop.
Save zilahir/5fcf81186cfc5acb099c5590721a3b92 to your computer and use it in GitHub Desktop.
send message to slack using firebase cloud function
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