diff --git a/Dockerfile b/Dockerfile index 3cdff29..83edd1c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.8-slim EXPOSE 4785 -RUN pip3 install --no-cache-dir matrix-nio +RUN pip3 install --no-cache-dir markdown matrix-nio ADD matrix_webhook.py / diff --git a/README.md b/README.md index 9088815..38d2619 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,6 @@ docker-compose up -d ## Test / Usage ``` -curl -d '{"text":"new contrib from toto: http://radio.localhost/map/#44", "key": "secret"}' 'matrixwebhook.localhost/!FwpsPdeIYWcXDVpRmO:matrix.org' +curl -d '{"text":"new contrib from toto: [44](http://radio.localhost/map/#44)", "key": "secret"}' 'matrixwebhook.localhost/!FwpsPdeIYWcXDVpRmO:matrix.org' ``` (or localhost:4785 without docker) diff --git a/matrix_webhook.py b/matrix_webhook.py index 06fc5a5..6f18f75 100755 --- a/matrix_webhook.py +++ b/matrix_webhook.py @@ -4,7 +4,7 @@ Matrix Webhook. Post a message to a matrix room with a simple HTTP POST v1: matrix-client & http.server -v2: matrix-nio & aiohttp +v2: matrix-nio & aiohttp & markdown """ import asyncio @@ -13,6 +13,8 @@ import os from http import HTTPStatus from signal import SIGINT, SIGTERM +from markdown import markdown + from aiohttp import web from nio import AsyncClient @@ -42,6 +44,8 @@ async def handler(request): content={ "msgtype": "m.text", "body": data['text'], + "format": "org.matrix.custom.html", + "formatted_body": markdown(data['text']), }) return web.Response(text='{"status": %i, "ret": "%s"}' % (status, ret),