diff --git a/core/mail/protocol.py b/core/mail/protocol.py index 2a175c5..2259608 100644 --- a/core/mail/protocol.py +++ b/core/mail/protocol.py @@ -276,7 +276,7 @@ class LMTPHandler: if thread: await channel_layer.group_send( 'general', {"type": "generic.event", "name": "user_notification", "event_id": systemevent.id, - "ticket": thread, "new": new}) + "ticket_id": thread.id, "new": new}) if new and reply: log.info('Sending message to %s' % reply['To']) await send_smtp(reply) diff --git a/core/notifications/dispatch.py b/core/notifications/dispatch.py index c224f1d..37494a0 100644 --- a/core/notifications/dispatch.py +++ b/core/notifications/dispatch.py @@ -7,6 +7,7 @@ from core.settings import TELEGRAM_BOT_TOKEN, TELEGRAM_GROUP_CHAT_ID from mail.protocol import send_smtp, make_notification from notifications.models import UserNotificationChannel from notifications.templates import render_notification_new_ticket, render_notification_reply_ticket +from tickets.models import IssueThread async def http_get(url): @@ -26,6 +27,7 @@ async def email_notify(message, email): await send_smtp(mail) + class NotificationDispatcher: channel_layer = None room_group_name = "general" @@ -40,6 +42,10 @@ class NotificationDispatcher: channels = UserNotificationChannel.objects.filter(active=True) return list(channels) + @database_sync_to_async + def get_ticket(self, ticket_id): + return IssueThread.objects.get(id=ticket_id) + async def run_forever(self): # Infinite loop to continuously listen for messages print("Listening for messages...") @@ -52,8 +58,9 @@ class NotificationDispatcher: if (message and 'type' in message and message['type'] == 'generic.event' and 'name' in message and message['name'] == 'user_notification'): - if 'ticket' in message and 'event_id' in message and 'new' in message: - await self.dispatch(message['ticket'], message['event_id'], message['new']) + if 'ticket_id' in message and 'event_id' in message and 'new' in message: + ticket = await self.get_ticket(message['ticket_id']) + await self.dispatch(ticket, message['event_id'], message['new']) else: print("Error: Invalid message format")