stash
This commit is contained in:
parent
5ddd8c0b4b
commit
b3bf2bfc31
2 changed files with 10 additions and 3 deletions
|
@ -276,7 +276,7 @@ class LMTPHandler:
|
||||||
if thread:
|
if thread:
|
||||||
await channel_layer.group_send(
|
await channel_layer.group_send(
|
||||||
'general', {"type": "generic.event", "name": "user_notification", "event_id": systemevent.id,
|
'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:
|
if new and reply:
|
||||||
log.info('Sending message to %s' % reply['To'])
|
log.info('Sending message to %s' % reply['To'])
|
||||||
await send_smtp(reply)
|
await send_smtp(reply)
|
||||||
|
|
|
@ -7,6 +7,7 @@ from core.settings import TELEGRAM_BOT_TOKEN, TELEGRAM_GROUP_CHAT_ID
|
||||||
from mail.protocol import send_smtp, make_notification
|
from mail.protocol import send_smtp, make_notification
|
||||||
from notifications.models import UserNotificationChannel
|
from notifications.models import UserNotificationChannel
|
||||||
from notifications.templates import render_notification_new_ticket, render_notification_reply_ticket
|
from notifications.templates import render_notification_new_ticket, render_notification_reply_ticket
|
||||||
|
from tickets.models import IssueThread
|
||||||
|
|
||||||
|
|
||||||
async def http_get(url):
|
async def http_get(url):
|
||||||
|
@ -26,6 +27,7 @@ async def email_notify(message, email):
|
||||||
await send_smtp(mail)
|
await send_smtp(mail)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class NotificationDispatcher:
|
class NotificationDispatcher:
|
||||||
channel_layer = None
|
channel_layer = None
|
||||||
room_group_name = "general"
|
room_group_name = "general"
|
||||||
|
@ -40,6 +42,10 @@ class NotificationDispatcher:
|
||||||
channels = UserNotificationChannel.objects.filter(active=True)
|
channels = UserNotificationChannel.objects.filter(active=True)
|
||||||
return list(channels)
|
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):
|
async def run_forever(self):
|
||||||
# Infinite loop to continuously listen for messages
|
# Infinite loop to continuously listen for messages
|
||||||
print("Listening 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
|
if (message and 'type' in message and message['type'] == 'generic.event' and 'name' in message and
|
||||||
message['name'] == 'user_notification'):
|
message['name'] == 'user_notification'):
|
||||||
if 'ticket' in message and 'event_id' in message and 'new' in message:
|
if 'ticket_id' in message and 'event_id' in message and 'new' in message:
|
||||||
await self.dispatch(message['ticket'], message['event_id'], message['new'])
|
ticket = await self.get_ticket(message['ticket_id'])
|
||||||
|
await self.dispatch(ticket, message['event_id'], message['new'])
|
||||||
else:
|
else:
|
||||||
print("Error: Invalid message format")
|
print("Error: Invalid message format")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue