Skip to content

Instantly share code, notes, and snippets.

@johncmckim
Created September 4, 2016 07:15
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 johncmckim/9210d15be5eec8692e1dbcbe3b216a92 to your computer and use it in GitHub Desktop.
Save johncmckim/9210d15be5eec8692e1dbcbe3b216a92 to your computer and use it in GitHub Desktop.
Garden Aid - Chat - Slack Webhook
const BbPromise = require('bluebird');
const rp = require('request-promise');
module.exports.notify = (event, context, cb) => {
const promises = [];
event.Records.forEach(function(record) {
if(record.EventSource !== 'aws:sns') {
console.warn('Recieved non sns event: ', record);
return;
}
const notification = JSON.parse(record.Sns.Message);
const options = {
method: 'POST',
uri: process.env.slackWebHookUrl,
json: true,
body: {
text: notification.message,
},
};
promises.push(rp(options));
});
return BbPromise.all(promises)
.then(() => cb(null, { message: 'success' })
.catch(cb);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment