From 98cd9362aa87ae2d3e86e71a6450a257e2285c5d Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Sun, 30 May 2021 16:34:09 +0200 Subject: [PATCH 1/2] Add HOST to PORT configuration, and document both Co-authored-by: Sven Seeberg --- README.md | 2 ++ matrix_webhook.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ca3fe6d..7e6229b 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ environment variables: - `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 diff --git a/matrix_webhook.py b/matrix_webhook.py index 2f8482e..b8b02a4 100755 --- a/matrix_webhook.py +++ b/matrix_webhook.py @@ -18,7 +18,7 @@ from markdown import markdown from nio import AsyncClient from nio.exceptions import LocalProtocolError -SERVER_ADDRESS = ('', int(os.environ.get('PORT', 4785))) +SERVER_ADDRESS = (os.environ.get('INTERFACE', None), int(os.environ.get('PORT', 4785))) MATRIX_URL = os.environ.get('MATRIX_URL', 'https://matrix.org') MATRIX_ID = os.environ.get('MATRIX_ID', '@wwm:matrix.org') MATRIX_PW = os.environ['MATRIX_PW'] From 2499832e1c69cb96d272fbbfe03a6bf90536d5a0 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Sun, 30 May 2021 16:40:01 +0200 Subject: [PATCH 2/2] use aiohttp.web.BaseRequest.path instead of rel_url Co-authored-by: Sven Seeberg --- matrix_webhook.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matrix_webhook.py b/matrix_webhook.py index b8b02a4..87b3664 100755 --- a/matrix_webhook.py +++ b/matrix_webhook.py @@ -18,7 +18,7 @@ from markdown import markdown from nio import AsyncClient from nio.exceptions import LocalProtocolError -SERVER_ADDRESS = (os.environ.get('INTERFACE', None), int(os.environ.get('PORT', 4785))) +SERVER_ADDRESS = (os.environ.get('INTERFACE', ''), int(os.environ.get('PORT', 4785))) MATRIX_URL = os.environ.get('MATRIX_URL', 'https://matrix.org') MATRIX_ID = os.environ.get('MATRIX_ID', '@wwm:matrix.org') MATRIX_PW = os.environ['MATRIX_PW'] @@ -46,7 +46,7 @@ async def handler(request): if data['key'] != API_KEY: return create_json_response(HTTPStatus.UNAUTHORIZED, 'Invalid API key') - room_id = str(request.rel_url)[1:] + room_id = request.path[1:] content = { 'msgtype': 'm.text', 'body': data['text'],