Skip to content
Snippets Groups Projects
README.md 2.86 KiB
Newer Older
# Matrix Webhook
Robert Test's avatar
Robert Test committed

Guilhem Saurel's avatar
Guilhem Saurel committed
[![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)
Guilhem Saurel's avatar
Guilhem Saurel committed
[![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)

Post a message to a matrix room with a simple HTTP POST
Guilhem Saurel's avatar
Guilhem Saurel committed

Guilhem Saurel's avatar
Guilhem Saurel committed
## Install
Guilhem Saurel's avatar
Guilhem Saurel committed

Guilhem Saurel's avatar
Guilhem Saurel committed
```
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
```
Guilhem Saurel's avatar
Guilhem Saurel committed


## Dev

```
Guilhem Saurel's avatar
Guilhem Saurel committed
poetry install
# or python3 -m pip install --user markdown matrix-nio
python3 -m matrix_webhook
Guilhem Saurel's avatar
Guilhem Saurel committed
```

## Prod

Guilhem Saurel's avatar
Guilhem Saurel committed
A `docker-compose.yml` is provided:

Guilhem Saurel's avatar
Guilhem Saurel committed
- Use [Traefik](https://traefik.io/) on the `web` docker network, eg. with
  [proxyta.net](https://framagit.org/oxyta.net/proxyta.net)
Guilhem Saurel's avatar
Guilhem Saurel committed
- Put the configuration into a `.env` file
Guilhem Saurel's avatar
Guilhem Saurel committed
- Configure your DNS for `${CHATONS_SERVICE:-matrixwebhook}.${CHATONS_DOMAIN:-localhost}`
Guilhem Saurel's avatar
Guilhem Saurel committed

```
docker-compose up -d
```

Guilhem Saurel's avatar
Guilhem Saurel committed
## Test / Usage
Guilhem Saurel's avatar
Guilhem Saurel committed

```
Guilhem Saurel's avatar
Guilhem Saurel committed
curl -d '{"text":"new contrib from toto: [44](http://radio.localhost/map/#44)", "key": "secret"}' \
  'http://matrixwebhook.localhost/!DPrUlnwOhBEfYwsDLh:matrix.org'
Guilhem Saurel's avatar
Guilhem Saurel committed
```
(or localhost:4785 without docker)
Guilhem Saurel's avatar
Guilhem Saurel committed

## Test room

Guilhem Saurel's avatar
Guilhem Saurel committed
#matrix-webhook:tetaneutral.net](https://matrix.to/#/!DPrUlnwOhBEfYwsDLh:matrix.org?via=laas.fr&via=tetaneutral.net&via=aen.im)

## Unit tests

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