Last active
February 17, 2017 14:41
-
-
Save malko/f60be2793e1d85d0b6fde446339506d4 to your computer and use it in GitHub Desktop.
outgoing rocketchat webhook to create polls
This file contains 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
/* | |
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