Skip to content

Instantly share code, notes, and snippets.

@malko
Last active February 17, 2017 14:41
Show Gist options
  • Save malko/f60be2793e1d85d0b6fde446339506d4 to your computer and use it in GitHub Desktop.
Save malko/f60be2793e1d85d0b6fde446339506d4 to your computer and use it in GitHub Desktop.
outgoing rocketchat webhook to create polls
/*
EXAMPLE MESSAGE
!poll question?
option 1
option 2
*/
class Script {
/**
* @params {object} request
*/
prepare_outgoing_request({ request }) {
const emojis = [
':zero:',
':one:',
':two:',
':three:',
':four:',
':five:',
':six:',
':seven:',
':eight:',
':nine:',
':ten:',
];
const [question, ...choices] = request.data.text.split(/\r?\n/g);
return {
message: {
text: '\n_Please vote using reactions_',
attachments: [
{
color: '#0000DD',
title: question.replace(/^\s*!poll\s*/, ''),
text: choices.map((choice, id) => `${emojis[id + 1]} ${choice}`).join('\n'),
},
],
},
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment