Created
September 4, 2016 07:15
-
-
Save johncmckim/9210d15be5eec8692e1dbcbe3b216a92 to your computer and use it in GitHub Desktop.
Garden Aid - Chat - Slack Webhook
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
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