Skip to content

Instantly share code, notes, and snippets.

@deptno
Created August 29, 2016 05:55
Show Gist options
  • Save deptno/f608e6c7c85614b39a46bbcb355389df to your computer and use it in GitHub Desktop.
Save deptno/f608e6c7c85614b39a46bbcb355389df to your computer and use it in GitHub Desktop.
for aws lambda
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