Skip to content

Instantly share code, notes, and snippets.

@leigh-johnson
Last active November 29, 2016 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leigh-johnson/a691b280a294462f33faccaf286f5318 to your computer and use it in GitHub Desktop.
Save leigh-johnson/a691b280a294462f33faccaf286f5318 to your computer and use it in GitHub Desktop.
const https = require('https');
const url = require('url');
const slack_url = 'your_slash_url';
const slack_req_opts = url.parse(slack_url);
slack_req_opts.method = 'POST';
slack_req_opts.headers = {
'Content-Type': 'application/json'
};
exports.handler = function(event, context) {
console.debug(`Battery health: ${event.batteryVoltage} mv`)
var req = https.request(slack_req_opts, function(res) {
if (res.statusCode === 200) {
context.succeed('posted to slack');
} else {
context.fail('status code: ' + res.statusCode);
}
});
// "clickType": "SINGLE | DOUBLE | LONG"
if (event.clickType == 'SINGLE'){
var payload = {
'text': '@here - Your sample msg',
'username': 'YourUserName',
'icon_emoji': ':ansible:'
}
}
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
context.fail(e.message);
});
req.write(JSON.stringify(payload));
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment