From 8a6db379e41967b1f3361f47260030fac2ab15f2 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 2 Jan 2021 10:13:07 +0100 Subject: [PATCH] Implement filter signals for message processing --- msgio/gateways/telegram.py | 5 ++++- msgio/handler.py | 3 ++- msgio/helpers.py | 12 ++++++++++++ requirements.txt | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/msgio/gateways/telegram.py b/msgio/gateways/telegram.py index d2d7bdb..02afe6d 100644 --- a/msgio/gateways/telegram.py +++ b/msgio/gateways/telegram.py @@ -9,6 +9,7 @@ from dbsettings.functions import dbsettings from ..signals import send_message from ..models import GatewayUser +from ..helpers import run_filters class TelegramWebhookView(View): def post(self, *args, **kwargs): @@ -29,4 +30,6 @@ def telegram_sender(sender, **kwargs): settings = GatewayUser.objects.get(user=notification.recipient, gateway="telegram") chat_id = settings.gatewayusersetting_set.get(key="chat_id").value - TelegramDispatcher().send(notification.content, chat_id) \ No newline at end of file + text = run_filters(notification) + + TelegramDispatcher().send(text, chat_id) \ No newline at end of file diff --git a/msgio/handler.py b/msgio/handler.py index 1a192a0..ec9413d 100644 --- a/msgio/handler.py +++ b/msgio/handler.py @@ -26,4 +26,5 @@ def send_notifications(sender, **kwargs): except: pass # TODO: See above - return returns \ No newline at end of file + return returns + diff --git a/msgio/helpers.py b/msgio/helpers.py index e69de29..d675fbe 100644 --- a/msgio/helpers.py +++ b/msgio/helpers.py @@ -0,0 +1,12 @@ +import filtersignals + +from dbsettings.functions import getValue + +make_message = filtersignals.FilterSignal() + +def run_filters(notification): + return make_message.send_robust(notification.__class__, recipient=notification.recipient, content=notification.content, app=notification.app)["content"] + +@filtersignals.receiver(make_message, 500) +def notification_placeholders(sender, **kwargs): + return {"content": kwargs["content"].replace("%KUMIFYURL%", getValue("KUMIFY_URL", "your Kumify instance"))} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 83c68f8..44b7f55 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,7 @@ django-multiupload django-storages git+git://github.com/Chive/django-multiupload.git@ba52e161a68ce19062c3655e89544c2d377990a0#egg=multiupload git+https://kumig.it/kumisystems/django-dbsettings.git +git+https://kumig.it/kumisystems/django-filtersignals.git mysqlclient boto3 argon2_cffi