rename project into Matrix Webhook

This commit is contained in:
Guilhem Saurel 2019-02-17 11:46:00 +01:00
parent 6d05f6bb94
commit 01a083c693
3 changed files with 11 additions and 13 deletions

View file

@ -1,6 +1,6 @@
# wifi-with-matrix # Matrix Webhook
Bridge between https://code.ffdn.org/FFDN/wifi-with-me & a matrix room Post a message to a matrix room with a simple HTTP POST
## Configuration ## Configuration
@ -30,6 +30,6 @@ docker-compose up -d
## Test ## Test
``` ```
curl -d '{"text":"new contrib from toto: http://radio.localhost/map/#44", "key": "secret"}' wwm.localhost curl -d '{"text":"new contrib from toto: http://radio.localhost/map/#44", "key": "secret"}' mwh.localhost
``` ```
(or wwm.localhost:4785 without docker) (or mwh.localhost:4785 without docker)

View file

@ -14,5 +14,4 @@ services:
- web - web
labels: labels:
traefik.enable: "true" traefik.enable: "true"
traefik.frontend.rule: "Host: ${CHATONS_SERVICE:-wwm}.${CHATONS_DOMAIN:-localhost}, www.${CHATONS_SERVICE:-wwm}.${CHATONS_DOMAIN:-localhost}" traefik.frontend.rule: "Host: ${CHATONS_SERVICE:-mwh}.${CHATONS_DOMAIN:-localhost}, www.${CHATONS_SERVICE:-mwh}.${CHATONS_DOMAIN:-localhost}"

13
main.py
View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
wifi-with-matrix script. Matrix Webhook
Bridge between https://code.ffdn.org/FFDN/wifi-with-me & a matrix room Post a message to a matrix room with a simple HTTP POST
""" """
import json import json
@ -17,9 +17,9 @@ MATRIX_PW = os.environ['MATRIX_PW']
API_KEY = os.environ['API_KEY'] API_KEY = os.environ['API_KEY']
class WWMBotServer(HTTPServer): class MatrixWebhookServer(HTTPServer):
""" """
an HTTPServer that also contain a matrix client an HTTPServer that embeds a matrix client
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -29,7 +29,7 @@ class WWMBotServer(HTTPServer):
self.rooms = self.client.get_rooms() self.rooms = self.client.get_rooms()
class WWMBotForwarder(BaseHTTPRequestHandler): class MatrixWebhookHandler(BaseHTTPRequestHandler):
""" """
Class given to the server, st. it knows what to do with a request. Class given to the server, st. it knows what to do with a request.
This one handles the HTTP request, and forwards it to the matrix room. This one handles the HTTP request, and forwards it to the matrix room.
@ -60,5 +60,4 @@ class WWMBotForwarder(BaseHTTPRequestHandler):
if __name__ == '__main__': if __name__ == '__main__':
print('Wifi-With-Matrix bridge starting…') MatrixWebhookServer(SERVER_ADDRESS, MatrixWebhookHandler).serve_forever()
WWMBotServer(SERVER_ADDRESS, WWMBotForwarder).serve_forever()