Post a message to a matrix room with a simple HTTP POST
Find a file
Guilhem Saurel c03ae0a571 lint: add flake8 configuration
Black allows up to 88 characters per line.

Put this configuration into a separated file, as pyproject.toml won't do
ref. https://github.com/PyCQA/flake8/issues/234
2021-08-27 18:15:58 +02:00
.github/workflows setup action to publish releases on github 2021-08-07 17:54:39 +02:00
matrix_webhook room_id can come from url, content, or parameters 2021-08-01 13:20:03 +02:00
tests update test for latest synapse docker image 2021-08-27 18:14:54 +02:00
.flake8 lint: add flake8 configuration 2021-08-27 18:15:58 +02:00
.gitignore details 2021-07-13 11:41:16 +02:00
.pre-commit-config.yaml update pre-commit 2021-07-13 11:41:51 +02:00
CHANGELOG.md update test for latest synapse docker image 2021-08-27 18:14:54 +02:00
docker-compose.yml remove the need for www 2020-06-07 10:31:21 +02:00
Dockerfile update README 2021-07-18 18:12:08 +02:00
LICENSE update year 2021-07-18 16:55:23 +02:00
poetry.lock poetry update 2021-07-18 16:56:59 +02:00
pyproject.toml v3.1.1 2021-07-18 22:59:49 +02:00
README.md ci: release also on github 2021-08-27 18:15:55 +02:00
test.yml clean tests 2021-07-13 11:41:16 +02:00

Matrix Webhook

Tests Lints Docker-Hub Release Code style: black codecov

Post a message to a matrix room with a simple HTTP POST

Install

python3 -m pip install matrix-webhook
# OR
docker pull nim65s/matrix-webhook

Start

Create a matrix user for the bot, make it join the rooms you want it to talk into, and launch it with the following arguments or environment variables:

python -m matrix_webhook -h
# OR
docker run --rm -it nim65s/matrix-webhook -h
usage: python -m matrix_webhook [-h] [-H HOST] [-P PORT] [-u MATRIX_URL] -i MATRIX_ID -p MATRIX_PW -k API_KEY [-v]

Configuration for Matrix Webhook.


optional arguments:
  -h, --help            show this help message and exit
  -H HOST, --host HOST  host to listen to. Default: `''`. Environment variable: `HOST`
  -P PORT, --port PORT  port to listed to. Default: 4785. Environment variable: `PORT`
  -u MATRIX_URL, --matrix-url MATRIX_URL
                        matrix homeserver url. Default: `https://matrix.org`. Environment variable: `MATRIX_URL`
  -i MATRIX_ID, --matrix-id MATRIX_ID
                        matrix user-id. Required. Environment variable: `MATRIX_ID`
  -p MATRIX_PW, --matrix-pw MATRIX_PW
                        matrix password. Required. Environment variable: `MATRIX_PW`
  -k API_KEY, --api-key API_KEY
                        shared secret to use this service. Required. Environment variable: `API_KEY`
  -v, --verbose         increment verbosity level

Dev

poetry install
# or python3 -m pip install --user markdown matrix-nio
python3 -m matrix_webhook

Prod

A docker-compose.yml is provided:

  • Use Traefik on the web docker network, eg. with proxyta.net
  • Put the configuration into a .env file
  • Configure your DNS for ${CHATONS_SERVICE:-matrixwebhook}.${CHATONS_DOMAIN:-localhost}
docker-compose up -d

Test / Usage

curl -d '{"body":"new contrib from toto: [44](http://radio.localhost/map/#44)", "key": "secret"}' \
  'http://matrixwebhook.localhost/!DPrUlnwOhBEfYwsDLh:matrix.org'

(or localhost:4785 without docker)

Grafana

Add a webhook with an URL like: `http://matrixwebhook.localhost/!DPrUlnwOhBEfYwsDLh:matrix.org?key=secret&formatter=grafana'

Test room

#matrix-webhook:tetaneutral.net

Unit tests

docker-compose -f test.yml up --exit-code-from tests --force-recreate --build