Skip to content

Commit

Permalink
notify_followup_webhooks used in email, so moving signal triggering code
Browse files Browse the repository at this point in the history
  • Loading branch information
samsplunks committed Apr 16, 2024
1 parent 0e96909 commit 79b7ce9
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions helpdesk/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,36 @@

logger = logging.getLogger(__name__)

# listener is loaded via app.py HelpdeskConfig.ready()
@receiver(update_ticket_done)
def notify_followup_webhooks(sender, followup, **kwargs):
def notify_followup_webhooks(followup):
urls = settings.HELPDESK_GET_FOLLOWUP_WEBHOOK_URLS()
if not urls:
return

# Serialize the ticket associated with the followup
from .serializers import TicketSerializer
ticket = followup.ticket
ticket.set_custom_field_values()
serialized_ticket = TicketSerializer(ticket).data

# Prepare the data to send
data = {
'ticket': serialized_ticket,
'queue_slug': ticket.queue.slug,
'followup_id': followup.id
}

for url in urls:
try:
requests.post(url, json=data, timeout=settings.HELPDESK_WEBHOOK_TIMEOUT)
except requests.exceptions.Timeout:
logger.error('Timeout while sending followup webhook to %s', url)


# listener is loaded via app.py HelpdeskConfig.ready()
@receiver(update_ticket_done)
def notify_followup_webhooks_receiver(sender, followup, **kwargs):
if sender == "update_ticket":
# Serialize the ticket associated with the followup
from .serializers import TicketSerializer
ticket = followup.ticket
ticket.set_custom_field_values()
serialized_ticket = TicketSerializer(ticket).data

# Prepare the data to send
data = {
'ticket': serialized_ticket,
'queue_slug': ticket.queue.slug,
'followup_id': followup.id
}

for url in urls:
try:
requests.post(url, json=data, timeout=settings.HELPDESK_WEBHOOK_TIMEOUT)
except requests.exceptions.Timeout:
logger.error('Timeout while sending followup webhook to %s', url)
notify_followup_webhooks(followup)


def send_new_ticket_webhook(ticket):
Expand Down

0 comments on commit 79b7ce9

Please sign in to comment.