Post a message to a matrix room with a simple HTTP POST
Find a file
2023-01-17 14:11:28 -05:00
docs fix changelog 2021-08-28 00:08:56 +02:00
matrix_webhook add whitelist check to AbuseIPDB check 2022-12-08 20:29:01 -05:00
tests merge upstream changes 2022-11-29 22:08:43 -05:00
.flake8 lint: add flake8 configuration 2021-08-27 18:15:58 +02:00
.gitignore Add gitlab formatter 2022-03-03 19:17:40 +01:00
.pre-commit-config.yaml [pre-commit.ci] pre-commit autoupdate 2022-11-28 20:10:31 +00:00
CHANGELOG.md merge upstream changes 2022-11-29 22:08:43 -05:00
config-dist.yaml docs: updates to config-dist.yaml 2023-01-17 14:11:28 -05:00
docker-compose.yml docker: use image from docker hub 2021-09-12 15:55:10 +02:00
Dockerfile update README 2021-07-18 18:12:08 +02:00
LICENSE update year 2021-07-18 16:55:23 +02:00
package-lock.json add package*.json 2022-11-29 22:11:08 -05:00
package.json add package*.json 2022-11-29 22:11:08 -05:00
poetry.lock add pyyaml dep 2022-11-29 22:22:30 -05:00
pyproject.toml add pyyaml dep 2022-11-29 22:22:30 -05:00
README.md docs: basic readme change from the upstream version 2023-01-17 13:36:50 -05:00
test.yml clean tests 2021-07-13 11:41:16 +02:00

Matrix Webhook

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

This is my own fork of https://github.com/nim65s/matrix-webhook It adds a yaml configuration with multi-api key endpoints and moves the filtes to more of a plugin-based system

Install

For now, clone this repo and run pip install .

Start

Create a matrix user for the bot, and launch this app with the following arguments and/or environment variables (environment variables update defaults, arguments take precedence):

matrix-webhook -h
# OR
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_KEYS]
                                [-c CONFIG] [-v]

Configuration for Matrix Webhook.

options:
  -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_KEYS, --api-keys API_KEYS
                        comma separated list of shared secrets to use this
                        service. Required. Environment variable: `API_KEYS`
  -c CONFIG, --config CONFIG
                        configuration file. Default: `config.yaml`
  -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)

Formatters

These formatters will output custom messages depending on the specific formatter. Generally to set these up, on the remote provider you would create a webhook with https://your.webhook.domain/?formatter=<formatter columun below>&api_key=<your apikey>

formatter description key location
github for github.com in github JSON webhook settings as secret
grafana for grafana in webhook URL with api_key=<yourkey>
pingdom for pingdom.com in webhook URL with api_key=<yourkey>
buildbot buildbot reporter in webhook URL with api_key=<yourkey> or in master.cfg credentials header as api_key
generic returns raw JSON that was recieved. For developing additional formatter plugins in URL with api_key=

For example, if your matrix-webhook was hosted at https://webhooks.example.com, and you were setting up pingdom and you have an api_key of "123", you would use the following URL for your webhook call from pingdom: https://webhooks.example.com/?formatter=pingdom&api_key=123

For Gitlab

At a group level, Gitlab does not permit to setup webhooks. A workaround consists to use Google Chat or Microsoft Teams notification integration with a custom URL (Gitlab does not check if the url begins with the normal url of the service).

Google Chat

Add a Google Chat integration with an URL ending with ?formatter=gitlab_gchat&key=API_KEY

Microsoft Teams

Add a Microsoft Teams integration with an URL ending with ?formatter=gitlab_teams&key=API_KEY

Test room

#matrix-webhook:tetaneutral.net

Unit tests

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