Throw Incoming Webhooks to Mattermost in Python

I set it to allow overwriting of Mattermost's username and icon, and posted it to Mattermost using Python.

I had to use a webhook to throw a message to the self-hosted Mattermost, so I investigated it. The project I'm currently working on makes heavy use of Python, so I tried to find out if it could be done with Python.

Processing on the Python side

Posting a message to Mattermost simply throws an http post, so I was wondering if I needed a special library. When I looked it up, I found a library mattermostdriver that looks good, so I decided to use that.

Easy to use

  1. install
% poetry add mattermostdriver
#For pip:
% pip install mattermostdriver
  1. Use it like the following
    mattermost_driver = Driver({
        'scheme': 'https',
        'url': 'mattermost.your-domain.com',
        'port': 443,
    })
    webhook_id = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
    mattermost_driver.webhooks.call_webhook(hook_id=webhook_id, options={
        "username": "my-bot",
        "icon_url": "https://www.mattermost.org/wp-content/uploads/2016/04/icon.png ",
        "text": "Hello, this is some text\nThis is from python script. :tada:",
    })

You can now post from python

Mattermost settings

There were quite a few stumbling points, For some reason, even if I specified username and icon_url, it didn't change.

After a little research, it was necessary to change (+ restart) the config of mattermost. The following was detailed.

I changed the following settings and redeployed mattermost server.

/mattermost/config/config.json

        "EnablePostUsernameOverride": true,
        "EnablePostIconOverride": true,

After changing the settings, I confirmed that the username and icon were changed in the script created in Python.

You can see the same content from here.

That's it.

Recommended Posts

Throw Incoming Webhooks to Mattermost in Python
To flush stdout in Python
Login to website in Python
Speech to speech in python [text to speech]
How to develop in Python
Post to Slack in Python
[Python] How to do PCA in Python
Convert markdown to PDF in Python
How to use SQLite in Python
In the python command python points to python3.8
Try to calculate Trace in Python
Type specified in python. Throw exceptions
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
6 ways to string objects in Python
How to use PubChem in Python
How to handle Japanese in Python
An alternative to `pause` in Python
Throw something to Kinesis with python and make sure it's in
I tried to implement PLSA in Python
Try logging in to qiita with Python
How to access environment variables in Python
I tried to implement permutation in Python
How to dynamically define variables in Python
How to do R chartr () in Python
Pin current directory to script directory in Python
[Itertools.permutations] How to put permutations in Python
PUT gzip directly to S3 in Python
Send email to multiple recipients in Python (Python 3)
Convert psd file to png in Python
Sample script to trap signals in Python
I tried to implement PLSA in Python 2
To set default encoding to utf-8 in python
Decorator to avoid UnicodeEncodeError in Python 3 print ()
How to work with BigQuery in Python
Log in to Slack using requests in Python
How to get a stacktrace in python
How to display multiplication table in python
Easy way to use Wikipedia in Python
How to extract polygon area in Python
How to check opencv version in python
I tried to implement ADALINE in Python
[Python] Pandas to fully understand in 10 minutes
Module to generate word N-gram in Python
To reference environment variables in Python in Blender
I wanted to solve ABC159 in Python
I tried to implement PPO in Python
How to switch python versions in cloud9
How to adjust image contrast in Python
How to use __slots__ in Python class
How to dynamically zero pad in Python
Manage python packages to install in containers
To work with timestamp stations in Python
How to use regular expressions in Python
Convert from Markdown to HTML in Python
How to display Hello world in python
Adding Series to columns in python pandas
How to use is and == in Python
How to write Ruby to_s in Python
Introduction to Vectors: Linear Algebra in Python <1>