Skip to content

Instantly share code, notes, and snippets.

@palmerabollo
Last active December 2, 2015 09:34
Show Gist options
  • Select an option

  • Save palmerabollo/6ad67a9575c897327869 to your computer and use it in GitHub Desktop.

Select an option

Save palmerabollo/6ad67a9575c897327869 to your computer and use it in GitHub Desktop.
Tokbox meet room for Slack
module['exports'] = function tokbox(hook) {
var request = require('request');
// The parameters passed in via the slash command POST request.
var params = hook.params;
console.log(JSON.stringify(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.tokbox_command_token) {
hook.res.end('Incorrect token');
}
var channel = '#' + params.channel_name;
var room = params.channel_name;
if (params.channel_name === 'directmessage') {
if (!params.text) {
return hook.res.end('In a direct message you must add the username (e.g. /tokbok guido)');
}
channel = '@' + params.text.replace(/@/g, '');
room = params.user_name
}
console.log('channel', channel);
console.log('room', room);
// Set up the options for the HTTP request to the Webhook URL from the Slack Incoming Webhooks integration.
var options = {
uri: hook.env.tokbox_incoming_uri,
method: 'POST',
json: {
'text': '@' + params.user_name + ' wanna meet https://meet.tokbox.com/p2p-tdaf-' + room + '\nMeetings are toxic.',
'parse': 'full',
'channel': '#' + params.channel_name
}
};
request(options, function (error, response, body) {
if (error) {
return hook.res.end(error.message);
}
if (body === "Invalid channel specified") {
hook.res.end('Error. Invalid channel specified.');
}
// Finally, send the response. This will be displayed to the slack user.
hook.res.end('Meeting room created. Remember that meetings are toxic.');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment