From e01236c3a0a9f3fe85845e1b9b1536276dc39f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Mon, 14 Aug 2023 09:21:49 +0200 Subject: [PATCH] Add the /plain hook --- signal_webhook/app.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/signal_webhook/app.py b/signal_webhook/app.py index 2a80037..c9fd06e 100644 --- a/signal_webhook/app.py +++ b/signal_webhook/app.py @@ -53,3 +53,24 @@ def alertmanager(recipient=None): signal.signal_send(recipient_nums, msg) return "OK", 200 + + +@app.route("/plain", methods=["POST"]) +def plain(): + """Send a message through Signal, plain POST args. + + Expects: + * message: plaintext message to be sent; + * recipient: ID of recipient. If absent, default recipient is used. + """ + + if "message" not in request.form: + return "Missing message", 400 + recipient = request.form.get("recipient", configuration.DEFAULT_RECIPIENT) + try: + recipient_num = configuration.RECIPIENTS[recipient] + except KeyError: + return "Unauthorized recipient", 400 + + signal.signal_send([recipient_num], request.form["message"]) + return "OK", 200