Created
August 29, 2016 05:55
-
-
Save deptno/f608e6c7c85614b39a46bbcb355389df to your computer and use it in GitHub Desktop.
for aws lambda
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
import fetch from 'node-fetch'; | |
export const toSlack = (event, context, callback) => { | |
const {target, message} = event; | |
if (!target || !message) { | |
return callback(ex, 'Error'); | |
} | |
const options = { headers: {'Content-Type': 'application/json'}, method: 'POST', body: JSON.stringify({text: message}) }; | |
return fetch(target, options) | |
.then(res => res.json()) | |
.then(json => { | |
callback(null, json); | |
return json; | |
}) | |
.catch(ex => { | |
callback(ex, 'Error'); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment