stash
This commit is contained in:
parent
0e4717cc1e
commit
5b0ad7b520
3 changed files with 26 additions and 20 deletions
|
@ -12,5 +12,5 @@ Your c3lf (Cloakroom + Lost&Found) Team'''
|
||||||
new_issue_notification = '''New issue "{{ ticket_name | limit_length }}" [{{ ticket_uuid }}] created
|
new_issue_notification = '''New issue "{{ ticket_name | limit_length }}" [{{ ticket_uuid }}] created
|
||||||
{{ ticket_url }}'''
|
{{ ticket_url }}'''
|
||||||
|
|
||||||
reply_issue_notification = '''Reply to issue "{{ ticket_name }}" [{{ ticket_uuid }}]
|
reply_issue_notification = '''Reply to issue "{{ ticket_name }}" [{{ ticket_uuid }}] (was {{ previous_state_pretty }})
|
||||||
{{ ticket_url }}'''
|
{{ ticket_url }}'''
|
||||||
|
|
|
@ -68,11 +68,11 @@ class NotificationDispatcher:
|
||||||
async def dispatch(self, ticket, event_id, new):
|
async def dispatch(self, ticket, event_id, new):
|
||||||
message = await render_notification_new_ticket_async(
|
message = await render_notification_new_ticket_async(
|
||||||
ticket) if new else await render_notification_reply_ticket_async(ticket)
|
ticket) if new else await render_notification_reply_ticket_async(ticket)
|
||||||
title = f"{ticket.name} [#{ticket.short_uuid()}]"
|
title = f"[#{ticket.short_uuid()}] {ticket.name}"
|
||||||
print("Dispatching message:", message, "with event_id:", event_id)
|
print("Dispatching message:", message, "with event_id:", event_id)
|
||||||
targets = await self.get_notification_targets()
|
targets = await self.get_notification_targets()
|
||||||
jobs = []
|
jobs = []
|
||||||
# jobs.append(telegram_notify(message, TELEGRAM_GROUP_CHAT_ID))
|
jobs.append(telegram_notify(message, TELEGRAM_GROUP_CHAT_ID))
|
||||||
for target in targets:
|
for target in targets:
|
||||||
if target.channel_type == 'telegram':
|
if target.channel_type == 'telegram':
|
||||||
print("Sending telegram notification to:", target.channel_target)
|
print("Sending telegram notification to:", target.channel_target)
|
||||||
|
|
|
@ -4,10 +4,8 @@ from core.settings import PRIMARY_HOST
|
||||||
|
|
||||||
from notifications.models import MessageTemplate
|
from notifications.models import MessageTemplate
|
||||||
|
|
||||||
# auto_reply_title = f"Re: {{ ticket_name }} [#{{ ticket_uuid }}]"
|
|
||||||
|
|
||||||
|
|
||||||
TEMLATE_VARS = ['ticket_name', 'ticket_uuid', 'ticket_id', 'ticket_url',
|
TEMLATE_VARS = ['ticket_name', 'ticket_uuid', 'ticket_id', 'ticket_url',
|
||||||
|
'current_state', 'previous_state', 'current_state_pretty', 'previous_state_pretty',
|
||||||
'event_slug', 'event_name',
|
'event_slug', 'event_name',
|
||||||
'username', 'user_nick',
|
'username', 'user_nick',
|
||||||
'web_host'] # TODO customer_name, tracking_code
|
'web_host'] # TODO customer_name, tracking_code
|
||||||
|
@ -26,10 +24,8 @@ def ticket_url(ticket):
|
||||||
|
|
||||||
def render_template(template, **kwargs):
|
def render_template(template, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
environment = jinja2.Environment()
|
environment = jinja2.Environment()
|
||||||
environment.filters['limit_length'] = limit_length
|
environment.filters['limit_length'] = limit_length
|
||||||
|
|
||||||
tmpl = MessageTemplate.objects.get(name=template)
|
tmpl = MessageTemplate.objects.get(name=template)
|
||||||
template = environment.from_string(tmpl.message)
|
template = environment.from_string(tmpl.message)
|
||||||
return template.render(**kwargs, web_host=PRIMARY_HOST)
|
return template.render(**kwargs, web_host=PRIMARY_HOST)
|
||||||
|
@ -37,27 +33,37 @@ def render_template(template, **kwargs):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_ticket_vars(ticket):
|
||||||
|
states = list(ticket.state_changes.order_by('-timestamp'))
|
||||||
|
return {
|
||||||
|
'ticket_name': ticket.name,
|
||||||
|
'ticket_uuid': ticket.short_uuid(),
|
||||||
|
'ticket_id': ticket.id,
|
||||||
|
'ticket_url': ticket_url(ticket),
|
||||||
|
'current_state': states[0].state if states else 'none',
|
||||||
|
'previous_state': states[1].state if len(states) > 1 else 'none',
|
||||||
|
'current_state_pretty': states[0].get_state_display() if states else 'none',
|
||||||
|
'previous_state_pretty': states[1].get_state_display() if len(states) > 1 else 'none',
|
||||||
|
'event_slug': ticket.event.slug if ticket.event else "37C3", # TODO 37C3 should not be hardcoded
|
||||||
|
'event_name': ticket.event.name if ticket.event else "37C3",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def render_auto_reply(ticket):
|
def render_auto_reply(ticket):
|
||||||
eventslug = ticket.event.slug if ticket.event else "37C3" # TODO 37C3 should not be hardcoded
|
return render_template('auto_reply', **get_ticket_vars(ticket))
|
||||||
return render_template('auto_reply', ticket_name=ticket.name, ticket_uuid=ticket.short_uuid(),
|
|
||||||
ticket_id=ticket.id, event_slug=eventslug, ticket_url=ticket_url(ticket))
|
|
||||||
|
|
||||||
|
|
||||||
def render_notification_new_ticket(ticket):
|
def render_notification_new_ticket(ticket):
|
||||||
eventslug = ticket.event.slug if ticket.event else "37C3" # TODO 37C3 should not be hardcoded
|
return render_template('new_issue_notification', **get_ticket_vars(ticket))
|
||||||
return render_template('new_issue_notification', ticket_name=ticket.name, ticket_uuid=ticket.short_uuid(),
|
|
||||||
ticket_id=ticket.id, event_slug=eventslug, ticket_url=ticket_url(ticket))
|
|
||||||
|
def render_notification_reply_ticket(ticket):
|
||||||
|
return render_template('reply_issue_notification', **get_ticket_vars(ticket))
|
||||||
|
|
||||||
|
|
||||||
async def render_notification_new_ticket_async(ticket):
|
async def render_notification_new_ticket_async(ticket):
|
||||||
return await database_sync_to_async(render_notification_new_ticket)(ticket)
|
return await database_sync_to_async(render_notification_new_ticket)(ticket)
|
||||||
|
|
||||||
|
|
||||||
def render_notification_reply_ticket(ticket):
|
|
||||||
eventslug = ticket.event.slug if ticket.event else "37C3" # TODO 37C3 should not be hardcoded
|
|
||||||
return render_template('reply_issue_notification', ticket_name=ticket.name, ticket_uuid=ticket.short_uuid(),
|
|
||||||
ticket_id=ticket.id, event_slug=eventslug, ticket_url=ticket_url(ticket))
|
|
||||||
|
|
||||||
|
|
||||||
async def render_notification_reply_ticket_async(ticket):
|
async def render_notification_reply_ticket_async(ticket):
|
||||||
return await database_sync_to_async(render_notification_reply_ticket)(ticket)
|
return await database_sync_to_async(render_notification_reply_ticket)(ticket)
|
||||||
|
|
Loading…
Reference in a new issue