Skip to main content

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

Project description

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)

For Github

Add a JSON webhook with ?formatter=github, and put the API_KEY as secret

For Grafana

Add a webhook with an URL ending with `?formatter=grafana&key=API_KEY'

Test room

#matrix-webhook:tetaneutral.net

Unit tests

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matrix-webhook-3.2.1.tar.gz (6.9 kB view hashes)

Uploaded Source

Built Distribution

matrix_webhook-3.2.1-py3-none-any.whl (7.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page