matterpoll-emoji for poll on Mattermost
This entry translated Qiita Entry for English learning.
What is matterpoll-emoji
?
I released the API named matterpoll-emoji
for Mattermost’s Custom Slash Command that post the message about poll.
kaakaa/matterpoll-emoji: Poll server for Mattermost
After creating poll command, you post the follow command.
/poll `What do you gys wanna grab for lunch?` :pizza: :sushi: :fried_shrimp: :spaghetti: :apple:
Then, matterpoll-emoji
posts the message about poll.
I tested matterpoll-emoji
on Mattermost version 3.7.
Usage
- Clone matterpoll-emoji
- Set your mm settings to config.json
- Run matterpoll-emoji server
- Create custom slash command on Mattermost
- Run slash command
See README.md for details.
Existing Problems
- Default one vote
- Mattermost Reaction needs one vote at least
- Recommended set bot user to matterpoll-emoji
- Mattermost API v3 based
- Mattermost released new API Version 4 (early beta release)
matterpoll-emoji
is based on API v3. API v3 will be supported until Sep. 16 2017
Mattermost Slash Command
The post started /
become “Slash Command” on Mattermost.
When typing /
on input box, then displayed the list of built-in command.
Custom Slash Command
User create new Slash Command from Integrations > Slash Commands
menu.
Setting Enable Custom Slash Commands
to true on System Console is needed.
Request Parameters
Custom Slash Command send the follow parameters to server specified on Request URL
in Custome Slash Command settings.
Creating Integrations with Commands
- Your integration should have a function for receiving HTTP POSTs or GETs from Mattermost that look like this example:
Content-Length: 244 User-Agent: Go 1.1 package http Host: localhost:5000 Accept: application/json Content-Type: application/x-www-form-urlencoded channel_id=cniah6qa73bjjjan6mzn11f4ie& channel_name=town-square& command=/somecommand& response_url=not+supported+yet& team_domain=someteam& team_id=rdc9bgriktyx9p4kowh3dmgqyc& text=hello+world& token=xr3j5x3p4pfk7kk6ck7b4e6ghh& user_id=c3a4cqe3dfy6dgopqt8ai3hydh& user_name=somename
mattepoll-emoji
parse the request parameters by golang url
package after combining dummy url.
poll_request.go#18
Response Parameters
Requested server sends the follow response to Mattermost server.
Creating Integrations with Commands
- If you want your integration to post a message back to the same channel, it can respond to the HTTP POST request from Mattermost with a JSON response body similar to this example:
{ "response_type": "in_channel", "text": "This is some response text.", "username": "robot", "icon_url": "https://www.mattermost.org/wp-content/uploads/2016/04/icon.png" }
If setting in_channel
to response_type
, then the server post the normal post to Lattermost. If setting ephemeral
, then posting the post like system message.
You set text
field the message that you wanna post.
username
and icon_url
is optional value.
That fields overrides name
and icon
of the post respectively.
Golang Driver
The server that is sent a request from Slash Command response a JSON, but that JSON cannot create any reactions to the post.
So matterpoll-emoji
use Golang Driver for creating the post and the reaction to it.
Golang Driver
has APIs about posts, users, channels and so on in model.Client
struct.
matterpoll-emoji
uses APIs about login
, post
and reaction
here.