Skip to content

Provides a slash command to create polls in Mattermost

License

Notifications You must be signed in to change notification settings

M-Mueller/mattermost-poll

Repository files navigation

Mattermost Poll

codecov

Provides a slash command to create polls in Mattermost.

Example

By default, a poll will only offer the options Yes and No. However, users can also specify an arbitrary number of choices:

Example

Choices are separated by --.

Additional options

  • --noprogress: Do not display the number of votes until the poll is ended
  • --public: Show who voted for what at the end of the poll
  • --votes=X: Allows users to place a total of X votes. Default is 1. Each individual option can still only be voted once.
  • --bars: Show results as a bar chart at the end of the poll.
  • --locale=X: Use a specific locale for the poll. Supported values are en and de. By default it's the users language.

Help

/poll help will display full usage options. Only visible to you.

Set the "Autocomplete Hint" in the Slash Command settings to See "/poll help" for full usage options

Requirements

  • Python >= 3.6
  • Flask
  • A WSGI server (e.g. gunicorn or uWSGI)

Setup

  1. In Mattermost go to Main Menu -> Integrations -> Slash Commands and add a new slash command with the URL of the server including the configured port number, e.g. http://localhost:5000.
  2. Choose POST for the request method.
  3. Copy the generated token.
  4. Copy settings.py.example to settings.py and customise your settings. Paste the token from the previous step in MATTERMOST_TOKENS.
  5. Start the server:
    gunicorn --workers 4 --bind :5000 app:app
  6. You might need to add the hostname of the poll server (e.g. localhost) to "System Settings > Developer > Allow untrusted internal connections to".

To resolve usernames in --public polls and to provide localization, the server needs access to the Mattermost API. For this a personal access token must be provided in your settings.py. Which user provides the token doesn't matter, e.g. you can create a dummy account. If no token is provided --public polls will not be available and all texts will be english.

Docker

To integrate with mattermost-docker:

  1. Create the integration in mattermost (see above). As URL use http://poll:5000 and add poll to the allowed untrusted connections. Also enable "Image Proxy" (see BAR_IMG_URL in settings.py.example for details)
  2. Copy docker-compose.poll.yml to the mattermost docker directory.
  3. Add the following two lines to your .env:
    MATTERMOST_POLL_PATH=./volumes/poll
    MATTERMOST_POLL_TOKENS="['<your-integration-token>']"
    MATTERMOST_POLL_PA_TOKEN="<your-access-token>"
    
  4. Include the service in the startup, e.g.:
    docker compose -f docker-compose.yml -f docker-compose.without-nginx.yml -f docker-compose.poll.yml up
    

The docker image reads all it's settings from environment variables (or uses a default value). See settings.py.docker for all available variables.