Skip to content

Instantly share code, notes, and snippets.

@thepauljones
Last active July 5, 2017 19:23
Show Gist options
  • Save thepauljones/e8cdaa6e5d5c14cd6b28 to your computer and use it in GitHub Desktop.
Save thepauljones/e8cdaa6e5d5c14cd6b28 to your computer and use it in GitHub Desktop.
Used to generate the link in rtl slack to the debug portal
module['exports'] = function highFive(hook) {
// hook.io has a range of node modules available - see
// https://hook.io/modules.
// We use request (https://www.npmjs.com/package/request) for an easy way to
// make the HTTP request.
var request = require('request');
// The parameters passed in via the slash command POST request.
var params = hook.params;
// Check that the hook has been triggered from our slash command by
// matching the token against the one in our environment variables.
if(params.token === hook.env.debug_token) {
// Set up the options for the HTTP request.
var options = {
uri : 'http://www.nothing.com',
method: 'POST'
};
// Make the POST request to the Slack incoming webhook.
request(options, function (error, response, body) {
// Pass error back to client if request endpoint can't be reached.
if (error) {
hook.res.end(error.message);
}
hook.res.writeHead(200, {
'Content-Type':'application/json'
});
var output = {};
var singleLink = hook.env.debug_url + params.text;
output.text = ''; //"<"+singleLink+"|" + singleLink+">";
var rtlXLLink = 'http://www.rtl.nl/xl/u/' + params.text;
output.attachments = [];
var attachment = {};
attachment.color = "#764FA5";
attachment.image_url = '';
attachment.image_url = 'https://api.qrserver.com/v1/create-qr-code/?data=' + rtlXLLink + '&size=100x100&margin=0';
attachment.text = "<" + singleLink + "|" + singleLink + "> \n RTLXL: " + "<" + rtlXLLink + " | " + rtlXLLink + ">";
attachment.pretext = 'Your debugger link is: ';
attachment.username = 'Paul Jones';
output.attachments.push(attachment);
// Finally, send the response. This will be displayed to the user after
// they submit the slash command.
hook.res.end(JSON.stringify(output));
});
} else {
// If the token didn't match, send a response anyway for debugging.
hook.res.end(params.token + ' ' + hook.env.debug_token + ' Incorrect token.');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment