markdown
ref https://matrix.org/docs/spec/client_server/r0.6.0#m-room-message-msgtypes
This commit is contained in:
parent
fc30487ead
commit
4b1acd874a
3 changed files with 7 additions and 3 deletions
|
@ -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 /
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue