From c9045d407d89776ebc49b7c98e928833179e115b Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Sun, 18 Jul 2021 18:12:08 +0200 Subject: [PATCH] update README --- Dockerfile | 4 +-- README.md | 62 ++++++++++++++++++++++++++++++-------- matrix_webhook/__main__.py | 1 - matrix_webhook/conf.py | 2 +- 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 688b216..2eb8198 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,6 @@ EXPOSE 4785 RUN pip install --no-cache-dir markdown matrix-nio -ADD matrix_webhook . +ADD matrix_webhook matrix_webhook -CMD python -m matrix_webhook +ENTRYPOINT ["python", "-m", "matrix_webhook"] diff --git a/README.md b/README.md index 02ebc4d..d9517ed 100644 --- a/README.md +++ b/README.md @@ -7,27 +7,59 @@ Post a message to a matrix room with a simple HTTP POST -## Configuration +## Install -Create a matrix user for the bot, make it join the rooms you want it to talk into, and then set the following -environment variables: +``` +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 +``` -- `MATRIX_URL`: the url of the matrix homeserver -- `MATRIX_ID`: the user id of the bot on this server -- `MATRIX_PW`: the password for this user -- `API_KEY`: a secret to share with the users of the service -- `HOST`: HOST to listen on, all interfaces if `''` (default). -- `PORT`: PORT to listed on, default to 4785. ## Dev ``` -pip3 install --user markdown matrix-nio -./matrix_webhook.py +poetry install +# or python3 -m pip install --user markdown matrix-nio +python3 -m matrix_webhook ``` ## Prod +A `docker-compose.yml` is provided: + - Use [Traefik](https://traefik.io/) on the `web` docker network, eg. with [proxyta.net](https://framagit.org/oxyta.net/proxyta.net) - Put the configuration into a `.env` file @@ -47,4 +79,10 @@ curl -d '{"text":"new contrib from toto: [44](http://radio.localhost/map/#44)", ## Test room -[#matrix-webhook:tetaneutral.net](https://matrix.to/#/!DPrUlnwOhBEfYwsDLh:matrix.org?via=laas.fr&via=tetaneutral.net&via=aen.im) +#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 +``` diff --git a/matrix_webhook/__main__.py b/matrix_webhook/__main__.py index 7b7db33..2b4a7d7 100644 --- a/matrix_webhook/__main__.py +++ b/matrix_webhook/__main__.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """ Matrix Webhook. diff --git a/matrix_webhook/conf.py b/matrix_webhook/conf.py index ae81672..fd39e02 100644 --- a/matrix_webhook/conf.py +++ b/matrix_webhook/conf.py @@ -2,7 +2,7 @@ import argparse import os -parser = argparse.ArgumentParser(description=__doc__) +parser = argparse.ArgumentParser(description=__doc__, prog="python -m matrix_webhook") parser.add_argument( "-H", "--host",