This commit is contained in:
jedi 2024-05-03 23:58:38 +02:00
parent 88ecfc0f61
commit 337bd9c885
2 changed files with 10 additions and 3 deletions

View file

@ -275,7 +275,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)

View file

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