Command-line Matrix notify tool and Flask application to provide a webhook for Matrix notifications.
Go to file
2024-05-29 13:12:21 +02:00
.run Update to Python 3.11 and Pipfile.lock 2024-02-05 17:33:14 +01:00
wmn Fix error message when config is missing 2024-05-29 13:12:21 +02:00
.gitignore Add pyproject.toml, refactor notify.py 2023-10-27 14:09:13 +02:00
config.yml.example Update to Flask 2 and matrix-nio 2021-06-28 09:56:48 +02:00
Dockerfile Remove VOLUME from Dockerfile 2024-02-05 17:45:17 +01:00
LICENSE Update to Python 3.11 and Pipfile.lock 2024-02-05 17:33:14 +01:00
Pipfile Test with Python 3.12, remove 3.11 requirement 2024-05-01 16:15:30 +02:00
Pipfile.lock Test with Python 3.12, remove 3.11 requirement 2024-05-01 16:15:30 +02:00
pyproject.toml Add pyproject.toml, refactor notify.py 2023-10-27 14:09:13 +02:00
README.md Update to Python 3.11 and Pipfile.lock 2024-02-05 17:33:14 +01:00
testrequest_gitlab.json Add better output for prometheus alerts 2020-09-27 17:55:20 +02:00
testrequest_prometheus.json Add better output for prometheus alerts 2020-09-27 17:55:20 +02:00

Webhook Matrix Notifier

This Python project, Webhook Matrix Notifier, is designed to receive data via webhooks, verify a secret, and send notifications to a Matrix room. The project provides a wsgi-compatible interface at wmn.wsgi, which is suitable for use behind a reverse proxy.

Configuration

An example configuration can be found at config.yml.example. By default, the project uses the config.yml file in the current working directory for configuration. To specify a different configuration file, use the WMN_CONFIG_PATH environment variable.

Running the Command Line Notifier

To notify a room with a simple text/html message, ensure your credentials are filled out in the configuration file and run:

python -m wmn.notify -r '!room:matrix.org' "text" "html"

The installation of the package, specified by pyproject.yaml will create a shorthand script called "matrix-notify" for this purpose.

Testing the Webhook Application Locally

  1. Start the local webserver using either env FLASK_APP=wmn.wsgi flask run or have your IDE start it for you.
  2. Send a POST request using curl.

GitLab

export URLQUOTED_ROOM=`python3 -c 'from urllib.parse import quote_plus; print(quote_plus("#room:matrix.org"))'`
curl -i -X POST "http://localhost:5000/matrix?room=${URLQUOTED_ROOM}" -H "X-Gitlab-Event: Push Hook" -H "X-Gitlab-Token: 123" -H "Content-Type: application/json" --data-binary @./testrequest_gitlab.json

Ensure that the X-Gitlab-Token corresponds to the secret provided in the configuration.

Prometheus

export URLQUOTED_ROOM=`python3 -c 'from urllib.parse import quote_plus; print(quote_plus("#room:matrix.org"))'`
export URLQUOTED_SECRET=`python3 -c 'from urllib.parse import quote_plus; print(quote_plus("123"))'`
curl -i -X POST "http://localhost:5000/matrix?type=prometheus&secret=${URLQUOTED_SECRET}&room=${URLQUOTED_ROOM}" -H "Content-Type: application/json" --data-binary @./testrequest_prometheus.json

Ensure that the secret is passed as a URI parameter.