django-helpdeskmig/helpdesk/webhooks.py

53 lines
1.5 KiB
Python
Raw Normal View History

2023-12-02 19:09:34 +01:00
from . import settings
import requests
import requests.exceptions
import logging
logger = logging.getLogger(__name__)
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
2023-12-02 19:09:34 +01:00
ticket = followup.ticket
ticket.set_custom_field_values()
2023-12-02 19:09:34 +01:00
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)
def send_new_ticket_webhook(ticket):
2023-12-02 19:09:34 +01:00
urls = settings.HELPDESK_GET_NEW_TICKET_WEBHOOK_URLS()
if not urls:
return
# Serialize the ticket
from .serializers import TicketSerializer
ticket.set_custom_field_values()
serialized_ticket = TicketSerializer(ticket).data
2023-12-02 19:09:34 +01:00
# Prepare the data to send
data = {
'ticket': serialized_ticket,
'queue_slug': ticket.queue.slug
2023-12-02 19:09:34 +01:00
}
for url in urls:
try:
requests.post(url, json=data, timeout=settings.HELPDESK_WEBHOOK_TIMEOUT)
except requests.exceptions.Timeout:
logger.error('Timeout while sending new ticket webhook to %s', url)