Skip to content

Instantly share code, notes, and snippets.

@bbirec
Last active June 28, 2016 03:02
Show Gist options
  • Select an option

  • Save bbirec/e3766527931263cae08a638132695455 to your computer and use it in GitHub Desktop.

Select an option

Save bbirec/e3766527931263cae08a638132695455 to your computer and use it in GitHub Desktop.
AWS Lambda function notifying to slack webhook from github release webhook.
'use strict';
let https = require('https');
let url = require('url');
let hookUrl = "https://hooks.slack.com/services/.....";
exports.handler = (event, context, callback) => {
var opt = url.parse(hookUrl);
opt.method = 'POST';
opt.headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
const req = https.request(opt, (res) => {
let body = '';
res.setEncoding('utf8');
res.on('data', (chunk) => body += chunk);
res.on('end', () => {
console.log('Successfully processed HTTPS response');
// If we know it's JSON, parse it
if (res.headers['content-type'] === 'application/json') {
body = JSON.parse(body);
}
callback(null, body);
});
});
req.on('error', callback);
var payload = {
username: event.sender.login,
icon_emoji: ":ghost:",
text: "<" + event.repository.url + "|" + event.repository.name + ">" + " 에 새로운 릴리즈가 추가되었습니다. " + "\n" +
"<" + event.release.html_url + "|" + event.release.tag_name + "> " + event.release.name + "\n" +
event.release.body
};
req.write("payload=" + JSON.stringify(payload));
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment