Implement filter signals for message processing

This commit is contained in:
Kumi 2021-01-02 10:13:07 +01:00
parent a1505bed44
commit 8a6db379e4
4 changed files with 19 additions and 2 deletions

View file

@ -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)
text = run_filters(notification)
TelegramDispatcher().send(text, chat_id)

View file

@ -27,3 +27,4 @@ def send_notifications(sender, **kwargs):
pass # TODO: See above
return returns

View file

@ -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"))}

View file

@ -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