kaakaa Blog

この世は極楽 空にはとんぼ

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. f:id:kaakaa_hoe:20170402213303p:plain

I tested matterpoll-emoji on Mattermost version 3.7.


  1. Clone matterpoll-emoji
  2. Set your mm settings to config.json
  3. Run matterpoll-emoji server
  4. Create custom slash command on Mattermost
  5. 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 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

  1. 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


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

  1. 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.