diff --git a/signal_webhook/app.py b/signal_webhook/app.py index b600c9a..2a80037 100644 --- a/signal_webhook/app.py +++ b/signal_webhook/app.py @@ -13,7 +13,8 @@ def root() -> t.Tuple[str, int]: @app.route("/alertmanager", methods=["POST"]) -def alertmanager(): +@app.route("/alertmanager/", methods=["POST"]) +def alertmanager(recipient=None): data = request.get_json(cache=False) if "version" not in data or int(data["version"]) != 4: @@ -42,6 +43,13 @@ def alertmanager(): msg += "\n\n" msg += "\n".join(["* " + line for line in alert_lines]) - signal.signal_send(configuration.RECIPIENTS[configuration.DEFAULT_RECIPIENT], msg) + if recipient is None: + recipient = configuration.DEFAULT_RECIPIENT + try: + recipient_nums = configuration.RECIPIENTS[recipient] + except KeyError: + return "Bad recipient", 400 + + signal.signal_send(recipient_nums, msg) return "OK", 200 diff --git a/signal_webhook/configuration.sample.py b/signal_webhook/configuration.sample.py index bc1920b..8869e32 100644 --- a/signal_webhook/configuration.sample.py +++ b/signal_webhook/configuration.sample.py @@ -1,5 +1,5 @@ # Signal 'address book' -RECIPIENTS = {"foo": "+42..."} # FIXME +RECIPIENTS = {"foo": ["+42..."]} # FIXME # Recipient from the dict above to send to by default DEFAULT_RECIPIENT = "foo" # FIXME diff --git a/signal_webhook/signal.py b/signal_webhook/signal.py index 636b5df..525122b 100644 --- a/signal_webhook/signal.py +++ b/signal_webhook/signal.py @@ -5,14 +5,14 @@ from gi.repository.GLib import GError logger = logging.getLogger(__name__) -def signal_send(recipient, message): +def signal_send(recipients, message): try: bus = SystemBus() signal_bus = bus.get("org.asamk.Signal") signal_bus.sendMessage( message, [], - [recipient], + recipients, ) except GError as exn: logger.error("Cannot send Signal notification: %s", exn)