Need help with mmpy_bot?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

150 Stars 70 Forks MIT License 197 Commits 19 Opened issues


A python based chat bot for MatterMost (

Services available


Need anything else?

Contributors list

PyPI Travis-Ci Codacy Maintainability Python Support Mattermost License

Documentation available at Read the Docs.

What is This

A python based chat bot for Mattermost.


  • Based on Mattermost WebSocket API(V4.0.0)
  • Simple plugins mechanism
  • Messages can be handled concurrently
  • Automatically reconnect to Mattermost when connection is lost
  • Python3 Support


| Mattermost | mmpy_bot | |------------------|:-----------:| | >= 4.0 | > 1.2.0 | | < 4.0 | unsupported |


pip install mmpy_bot



First you need create the mattermost email/password for your bot.

For use all API(V4.0.0), you need add bot user to system admin group to avoid 403 error.


Then you need to configure the

in a python module
, which must be located in a python import path.

SSL_VERIFY = True  # Whether to perform SSL cert verification
BOT_URL = 'http:///api/v4'  # with 'http://' and with '/api/v4' path. without trailing slash.
BOT_TOKEN = None # or '' if you have set bot personal access token.
BOT_TEAM = ''  # possible in lowercase
WEBHOOK_ID = '' # otherwise the bot will attempt to create one

Alternatively, you can use the environment variable



environment variable, which provide settings module
MATTERMOST_BOT_SETTINGS_MODULE=settings.bot_conf mmpy_bot

Run the bot

Use the built-in cli script and point to your custom settings file.

MATTERMOST_BOT_SETTINGS_MODULE=mmpy_bot_settings mmpy_bot

or you can create your own startup file. For example
from import Bot

if name == "main": Bot().run()

Now you can talk to your bot in your mattermost client!

Attachment Support

from import respond_to

@respond_to('webapi') def webapi_reply(message): attachments = [{ 'fallback': 'Fallback text', 'author_name': 'Author', 'author_link': '', 'text': 'Some text here ...', 'color': '#59afe1' }] message.reply_webapi( 'Attachments example', attachments, username='Mattermost-Bot', icon_url='', ) # Optional: Send message to specified channel # message.send_webapi('', attachments,

Integrations must be allowed for non admins users.

File Support

from import respond_to

@respond_to('files') def message_with_file(message): # upload_file() can upload only one file at a time # If you have several files to upload, you need call this function several times. file = open('test.txt') result = message.upload_file(file) file.close() if 'file_infos' not in result: message.reply('upload file error') file_id = result['file_infos'][0]['id'] # file_id need convert to array message.reply('hello', [file_id])


A chat bot is meaningless unless you can extend/customize it to fit your own use cases.

To write a new plugin, simply create a function decorated by
  • A function decorated with
    is called when a message matching the pattern is sent to the bot (direct message or @botname in a channel/group chat)
  • A function decorated with
    is called when a message matching the pattern is sent on a channel/group chat (not directly sent to the bot)
import re

from import listen_to from import respond_to

@respond_to('hi', re.IGNORECASE) def hi(message): message.reply('I can understand hi or HI!')

@respond_to('I love you') def love(message): message.reply('I love you too!')

@listen_to('Can someone help me?') def help_me(message): # Message is replied to the sender (prefixed with @user) message.reply('Yes, I can!')

# Message is sent on the channel
# message.send('I can help everybody!')

To extract params from the message, you can use regular expression: ```python from import respondto

@respondto('Give me (.*)') def giveme(message, something): message.reply('Here is %s' % something) ```

If you would like to have a command like 'stats' and 'stats startdate enddate', you can create reg ex like so:

from import respond_to
import re

@respond_to('stat$', re.IGNORECASE) @respond_to('stat (.) (.)', re.IGNORECASE) def stats(message, start_date=None, end_date=None): pass

If you don't want to expose some bot commands to public, you can add

like so:
@allow_only_direct_message() #only trigger by direct message, remove this line if you want call this in channel
@allowed_users('Your username or email address here','[email protected]') # List of usernames or e-mails allowed
@allowed_channels('allowed_channel_1','allowed_channel_2')  # List of allowed channels
def users_access(message):

Keep in mind the order matters!

must come before the "allowed" decorators.

And add the plugins module to

list of mmpybot settings, e.g.
    'devops.plugins',          # e.g. git submodule:  domain:devops-plugins.git
    'programmers.plugins',     # e.g. python package: package_name.plugins
    'frontend.plugins',        # e.g. project tree:

For example you can separate git repositories with plugins on your team.

If you are migrating from

to the
, and previously you are used
, you can use this battery without any problem. On most cases your plugins will be working properly if you are used standard API or with minimal modifications.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.