Skip to content

Instantly share code, notes, and snippets.

@patmandenver
Created December 17, 2017 22:09
Show Gist options
  • Save patmandenver/16f164d9ccd88af976d1fea21d8b92d4 to your computer and use it in GitHub Desktop.
Save patmandenver/16f164d9ccd88af976d1fea21d8b92d4 to your computer and use it in GitHub Desktop.
An AWS lambda slack webhook relay (make sure to change the path to your actual slack webhook URL
var https = require('https');
exports.handler = (event, context, callback) => {
console.log("MYLOG" + JSON.stringify(event))
//Custom Fields sent in from Distilio
var body = JSON.parse(event.body)
var name = body.name
var uri = body.uri
var text = body.text.substring(0, 120) //Don't want all the data
var post_data = JSON.stringify({
"username": "Distil.io",
"icon_emoji":":distillio:",
"channel": "#distillio",
"attachments": [
{
"color": "danger",
"fields": [
{
"title": name + " Website Changed!",
"value": "uri: " + uri
+ "\nbody: " + text,
"short": false
}
]
}
]
});
// An object of options to indicate where to post to
var post_options = {
host: 'hooks.slack.com',
port: '443',
path: '/services/YOURWEBHOOKHERE',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(post_data)
}
};
// Set up the request
var post_req = https.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});
// post the data
post_req.write(post_data);
post_req.end();
var details = {
"status": "OK"
}
var response = {
'statusCode': 200,
'headers': { 'Content-Type': 'application/json' },
'body': JSON.stringify(details)
}
console.log("LOG:: " + JSON.stringify(response))
callback(null, response);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment