Polls in RocketChat
1 min readOct 12, 2020
Here you will find information on how to install and use the Poll App inside the Rocketchat.
Prerequisite
Your work space must be registered in rocketchat cloud console.
Installation
You can install our Poll Rocket.Chat App from your Rocket.Chat Administration area.
- Go to Administration > Marketplace
- Search for the Poll app and click on the item
- Click on the Install button
Then
- Administration -> Integrations -> New Outgoing Webhook Integration
- Enabled:
true
- Channel: leave blank or set the channels (comma separated) you want this enabled in
- Trigger Words:
!poll
- URLs:
https://dev.null
- Post as:
rocket.cat
- Alias:
Rocket Poll
- Avatar URL:
https://cdn2.iconfinder.com/data/icons/Siena/256/poll%20green.png
- Script Enabled:
true
- Script: Paste the script below into this item
- Save
class Script {
@params {object} request
prepare_outgoing_request({ request })
{
const emojis = [
':zero:',
':one:',
':two:',
':three:',
':four:',
':five:',
':six:',
':seven:',
':eight:',
':nine:',
':ten:' ]; let match;
match = request.data.text.match(/((["'])(?:(?=(\\?))\3.)*?\2)/g); let title = '';
let options = [];
match.forEach((item, i) => {
item = item.replace(/(^['"]|['"]$)/g, '');
if (i === 0) {
title = item;
} else {
options.push(emojis[(options.length + 1)] + ' ' + item);
}
});
return {
message: {
text: '_Please vote using reactions_',
attachments: [
{
color: '#0000DD',
title: title,
text: options.join('\n')
}
]
}
};
}
process_outgoing_response({ request, response }) { }
}
Usage
In type message section, run this command accordingly to create a poll.
Usage: !poll "question?" "option 1" "option 2"