Skip to content

Instantly share code, notes, and snippets.

@sampaiodiego
Last active May 21, 2021 12:36
Show Gist options
  • Select an option

  • Save sampaiodiego/db4b60717e7ac0051024dde23c6a902e to your computer and use it in GitHub Desktop.

Select an option

Save sampaiodiego/db4b60717e7ac0051024dde23c6a902e to your computer and use it in GitHub Desktop.
/*
EXAMPLE MESSAGE
/poll "question?" "option 1" "option 2"
*/
/** Global Helpers
*
* console - A normal console instance
* _ - An underscore instance
* s - An underscore string instance
* HTTP - The Meteor HTTP object to do sync http calls
*/
class Script {
/**
* @params {object} request
*/
prepare_outgoing_request({ request }) {
// request.params {object}
// request.method {string}
// request.url {string}
// request.auth {string}
// request.headers {object}
// request.data.token {string}
// request.data.channel_id {string}
// request.data.channel_name {string}
// request.data.timestamp {date}
// request.data.user_id {string}
// request.data.user_name {string}
// request.data.text {string}
// request.data.trigger_word {string}
const emojis = [
':zero:',
':one:',
':two:',
':three:',
':four:',
':five:',
':six:',
':seven:',
':eight:',
':nine:',
':ten:'
];
let match;
// Change the URL and method of the request
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')
}
]
}
};
}
/**
* @params {object} request, response
*/
process_outgoing_response({ request, response }) {
}
}
@graywolf336

graywolf336 commented Jun 22, 2016

Copy link
Copy Markdown

How to Install

  1. Administration -> Integrations -> New Outgoing Webhook Integration
  2. Enabled: true
  3. Channel: leave blank or set the channels (comma separated) you want this enabled in
  4. Trigger Words: !poll
  5. URLs: https://dev.null
  6. Post as: rocket.cat
  7. Alias: Rocket Poll
  8. Avatar URL: https://cdn2.iconfinder.com/data/icons/Siena/256/poll%20green.png
  9. Script Enabled: true
  10. Script: Paste the script above into this item
  11. Save
  12. Usage: !poll "question?" "option 1" "option 2"

@IQ2022

IQ2022 commented Jun 23, 2016

Copy link
Copy Markdown

it works, to use this tool you need to make you pass the proper arguments between " "
image

@alefq

alefq commented Oct 18, 2016

Copy link
Copy Markdown

Great integration! Thank you for sharing.
In Rocket.chat v0.42.0 the trigger word (command) /poll did not worked.
Changing for _poll did the trick.

@ianubhav

ianubhav commented Nov 6, 2016

Copy link
Copy Markdown

Its not working says poll comand not found

@rtorrero

rtorrero commented Dec 2, 2016

Copy link
Copy Markdown

Not working here either, using Rocket.chat v.0.42.0 too. @alefq, do you mind sharing how you changed this exactly? I've tried with !, _ and /, still nothing.

@farewelldave

Copy link
Copy Markdown

Rocket.chat v0.46.0 this is working, however not with a trigger word of /poll, but if you use the trigger word of !poll or _poll it will work (at least it works for me on my server)

Make sure your trigger word is set to the "command" you will be using for the polling bot.

@benmcnelly

Copy link
Copy Markdown

Can confirm, !poll works fine as trigger

@rbycek

rbycek commented Mar 16, 2017

Copy link
Copy Markdown

When people respond to a poll, is there any way to get a total for each response? If that's built in, that doesn't seem to be working for me. (Rocket.Chat version 0.53.0

@wahnstom

Copy link
Copy Markdown

For me, also on 0.53.0, the poll renders fine, but does not issue a response at all. I've tried on FF, Chrome and Edge. Should I be expecting that you can click on one of the options to vote?

@justechn

Copy link
Copy Markdown

You cannot click on the options. At the top of the poll it says "Please vote using reactions". You have to find the number reaction icons and click on those. It would be great if the poll could automatically add those reactions so it is easier.

@sament

sament commented Jul 9, 2017

Copy link
Copy Markdown

Thanks for this. The setup worked very fine.

My poll results aren't showing. I noticed your example (refer image below) displays a counter '4 1'. Mine doesn't display any counter.
image

What am i doing wrong?
I am using version 0.56

Thanks!

@clegault

Copy link
Copy Markdown

Just to help folks understand how this is intended to work because it is not at all clear. In the italics in the example output you will see the actual instructions: "Please vote using reactions". This script does nothing but format a polling question in rocket.chat, it does not manage the poll results, nor does it provide an ability to vote. The users are expected to use the reactions capabilities in rocket.chat for that message to indicate their vote.

@designgurudotorg

Copy link
Copy Markdown

I like the simplicity of this solution but I've found it very confusing for users - they aren't sure how to respond and can't find the correct emoticon to use etc...

Have you looked at integrating one of these into RocketChat @sampaiodiego?
https://github.com/mfpierre/meteor-poll or:
https://github.com/aramk/meteor-voting-app

@ulope

ulope commented Oct 26, 2017

Copy link
Copy Markdown

Sorry to be blunt, but this isn't a solution at all. It's simply a formatting aid for the simplest part of a poll, namely displaying the options.

@mathabaws

mathabaws commented Jan 23, 2018

Copy link
Copy Markdown

Thanks for this. One small thing that would be nice is to change option :ten: to :keycap_ten: so the actual icon is shown.

@itsthejoker

Copy link
Copy Markdown

Does exactly what we need it to do. Thanks for publishing this!

@gudge25

gudge25 commented Dec 28, 2018

Copy link
Copy Markdown

i did according to instructions but variant are not click able (browser and application tested)

@marfraTUC

Copy link
Copy Markdown

Awsome simple feature. Thanks for sharing!

@rrzaripov

Copy link
Copy Markdown

Not work in 0.73.2

@fsejoseph

fsejoseph commented Mar 28, 2019

Copy link
Copy Markdown

@gudge I have the same issue. I can send it but no one can respond.

image

ghost commented Apr 8, 2019

Copy link
Copy Markdown

Response with reactions are supported.

@3x3cut0r

3x3cut0r commented Aug 22, 2019

Copy link
Copy Markdown

is there a way to implement some "filters"?
so that a user could only post one reaction to a poll?
or/and! that a user can only post a reaction that matches with one of the options?
other way this poll is quite useless ...

@sampaiodiego

Copy link
Copy Markdown
Author

@3x3cut0r please try out the Poll Rocket.Chat App, https://github.com/sampaiodiego/rocket.chat.app-poll

it is a improved version of this integration.

@starhound

Copy link
Copy Markdown

Does anyone know of a method to halt the initial "!poll" message from appearing, so that only the Webook response is posted?
-Thanks!

@wajeeh-devsinc

Copy link
Copy Markdown

@sampaiodiego I've installed it. After typing in the /poll command, form poops up. After filling all the required fields, I'm not able to create the poll because upon clicking Create button its not doing anything.

@sampaiodiego

Copy link
Copy Markdown
Author

@wajeeh-devsinc please post any issues on the app repository https://github.com/sampaiodiego/rocket.chat.app-poll

the issue you're describing looks like something with permissions.

@wajeeh-devsinc

wajeeh-devsinc commented Oct 19, 2020 via email

Copy link
Copy Markdown

@Prashant454

Copy link
Copy Markdown

Hello need help for full commadline creation of poll

am calling poll creation using
/api/v1/commands.run

with following params

{
"command": "poll",
"roomId":"zDSutedKQTqxY42D2",
"params": "'Question?' 'op1' 'op2'",
"triggerId":"NPgkh84FbQ6wsry2L"
}

it return success but in chat no polls are being created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment