Last active
December 2, 2015 09:34
-
-
Save palmerabollo/6ad67a9575c897327869 to your computer and use it in GitHub Desktop.
Tokbox meet room for Slack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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