matrix-webhook/README.md

126 lines
4.2 KiB
Markdown
Raw Normal View History

2019-02-17 05:46:00 -05:00
# Matrix Webhook
2019-02-10 16:02:48 -05:00
2021-07-13 06:28:01 -04:00
[![Tests](https://github.com/nim65s/matrix-webhook/actions/workflows/test.yml/badge.svg)](https://github.com/nim65s/matrix-webhook/actions/workflows/test.yml)
[![Lints](https://github.com/nim65s/matrix-webhook/actions/workflows/lint.yml/badge.svg)](https://github.com/nim65s/matrix-webhook/actions/workflows/lint.yml)
2021-07-18 15:09:51 -04:00
[![Docker-Hub](https://github.com/nim65s/matrix-webhook/actions/workflows/docker-hub.yml/badge.svg)](https://hub.docker.com/r/nim65s/matrix-webhook)
2021-08-27 11:49:11 -04:00
[![Release](https://github.com/nim65s/matrix-webhook/actions/workflows/release.yml/badge.svg)](https://pypi.org/project/matrix-webhook/)
2021-08-27 18:15:41 -04:00
2021-07-13 05:54:24 -04:00
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![codecov](https://codecov.io/gh/nim65s/matrix-webhook/branch/master/graph/badge.svg?token=BLGISGCYKG)](https://codecov.io/gh/nim65s/matrix-webhook)
2021-08-27 18:11:30 -04:00
[![PyPI version](https://badge.fury.io/py/matrix-webhook.svg)](https://badge.fury.io/py/matrix-webhook)
2021-07-13 05:54:24 -04:00
2019-02-17 05:46:00 -05:00
Post a message to a matrix room with a simple HTTP POST
2019-02-10 19:32:57 -05:00
2021-07-18 12:12:08 -04:00
## Install
2019-02-10 19:32:57 -05:00
2021-07-18 12:12:08 -04:00
```
python3 -m pip install matrix-webhook
# OR
docker pull nim65s/matrix-webhook
```
## Start
2021-09-28 05:05:32 -04:00
Create a matrix user for the bot, and launch this app it with the following arguments or environment variables:
2021-07-18 12:12:08 -04:00
```
python -m matrix_webhook -h
# OR
docker run --rm -it nim65s/matrix-webhook -h
```
```
2021-11-09 08:57:46 -05:00
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]
2021-07-18 12:12:08 -04:00
Configuration for Matrix Webhook.
2021-11-09 08:57:46 -05:00
options:
2021-07-18 12:12:08 -04:00
-h, --help show this help message and exit
2021-11-09 08:57:46 -05:00
-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`
2021-07-18 12:12:08 -04:00
-u MATRIX_URL, --matrix-url MATRIX_URL
2021-11-09 08:57:46 -05:00
matrix homeserver url. Default: `https://matrix.org`.
Environment variable: `MATRIX_URL`
2021-07-18 12:12:08 -04:00
-i MATRIX_ID, --matrix-id MATRIX_ID
2021-11-09 08:57:46 -05:00
matrix user-id. Required. Environment variable:
`MATRIX_ID`
2021-07-18 12:12:08 -04:00
-p MATRIX_PW, --matrix-pw MATRIX_PW
2021-11-09 08:57:46 -05:00
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`
2021-07-18 12:12:08 -04:00
-v, --verbose increment verbosity level
```
2019-02-10 19:32:57 -05:00
## Dev
```
2021-07-18 12:12:08 -04:00
poetry install
# or python3 -m pip install --user markdown matrix-nio
python3 -m matrix_webhook
2019-02-10 19:32:57 -05:00
```
## Prod
2021-07-18 12:12:08 -04:00
A `docker-compose.yml` is provided:
2019-02-17 06:29:50 -05:00
- Use [Traefik](https://traefik.io/) on the `web` docker network, eg. with
[proxyta.net](https://framagit.org/oxyta.net/proxyta.net)
2019-02-17 06:44:00 -05:00
- Put the configuration into a `.env` file
2020-06-07 04:31:21 -04:00
- Configure your DNS for `${CHATONS_SERVICE:-matrixwebhook}.${CHATONS_DOMAIN:-localhost}`
2019-02-10 19:32:57 -05:00
```
docker-compose up -d
```
2019-02-17 06:29:50 -05:00
## Test / Usage
2019-02-10 19:32:57 -05:00
```
2021-07-31 05:21:29 -04:00
curl -d '{"body":"new contrib from toto: [44](http://radio.localhost/map/#44)", "key": "secret"}' \
2020-03-14 13:10:32 -04:00
'http://matrixwebhook.localhost/!DPrUlnwOhBEfYwsDLh:matrix.org'
2019-02-10 19:32:57 -05:00
```
(or localhost:4785 without docker)
2020-03-14 12:17:01 -04:00
2021-08-27 14:05:08 -04:00
### For Github
2021-07-31 07:11:54 -04:00
2021-08-27 14:05:08 -04:00
Add a JSON webhook with `?formatter=github`, and put the `API_KEY` as secret
### For Grafana
2021-11-09 08:57:46 -05:00
Add a webhook with a URL ending with `?formatter=grafana&key=API_KEY`
### For Pingdom
Add a webhook with a URL ending with `?formatter=pingdom&key=API_KEY`
2021-07-31 07:11:54 -04:00
### For Buildgot
Add a webhook with a URL ending with `?formatter=buildbot&key=API_KEY`
### Generic formatter For anything that doesn't match specifically
This is most useful when developing a plugin. It will simply return the raw
json of whatever was sent. You *could* use this as a formatter, but it would
look pretty ugly.
Add a webhook with a URL ending with `?formatter=generic&key=API_KEY`
2020-03-14 12:17:01 -04:00
## Test room
2021-08-27 18:38:39 -04:00
[#matrix-webhook:tetaneutral.net](https://matrix.to/#/!DPrUlnwOhBEfYwsDLh:matrix.org)
2021-07-18 12:12:08 -04:00
## Unit tests
```
docker-compose -f test.yml up --exit-code-from tests --force-recreate --build
```