diff --git a/deploy/templates/app/intbot.env.example b/deploy/templates/app/intbot.env.example index ce35f62..1aadd3d 100644 --- a/deploy/templates/app/intbot.env.example +++ b/deploy/templates/app/intbot.env.example @@ -24,6 +24,11 @@ DISCORD_WEBSITE_CHANNEL_NAME="DISCORD_WEBSITE_CHANNEL_NAME" DISCORD_BOT_CHANNEL_ID="DISCORD_BOT_CHANNEL_ID" DISCORD_BOT_CHANNEL_NAME="DISCORD_BOT_CHANNEL_NAME" +DISCORD_HELPDESK_CHANNEL_ID="DISCORD_HELPDESK_CHANNEL_ID" +DISCORD_HELPDESK_CHANNEL_NAME="DISCORD_HELPDESK_CHANNEL_NAME" +DISCORD_BILLING_CHANNEL_ID="DISCORD_BILLING_CHANNEL_ID" +DISCORD_BILLING_CHANNEL_NAME="DISCORD_BILLING_CHANNEL_NAME" + # Webhooks WEBHOOK_INTERNAL_TOKEN="asdf" diff --git a/intbot/core/tasks.py b/intbot/core/tasks.py index 70d27f6..178de41 100644 --- a/intbot/core/tasks.py +++ b/intbot/core/tasks.py @@ -97,7 +97,7 @@ def process_zammad_webhook(wh: Webhook): DiscordMessage.objects.create( channel_id=channel.channel_id, channel_name=channel.channel_name, - content=f"Zammad: {wh.meta['message']}", + content=f"Zammad: {wh.extra['message']}", # Mark as unsent - to be sent with the next batch sent_at=None, ) diff --git a/intbot/tests/test_tasks.py b/intbot/tests/test_tasks.py index 9f209ac..4a571b7 100644 --- a/intbot/tests/test_tasks.py +++ b/intbot/tests/test_tasks.py @@ -5,7 +5,7 @@ import respx from core.integrations.github import GITHUB_API_URL from core.models import DiscordMessage, Webhook -from core.tasks import process_github_webhook, process_internal_webhook, process_webhook +from core.tasks import process_github_webhook, process_internal_webhook, process_webhook, process_zammad_webhook from django.utils import timezone from django_tasks.task import ResultStatus from httpx import Response @@ -167,3 +167,52 @@ def test_process_github_webhook_creates_a_message_from_supported( " from **Done** to **In progress**" ) assert dm.sent_at is None + + +@pytest.mark.django_db +@respx.mock +def test_process_zammad_webhook_creates_a_message_from_supported_queue(): + wh = Webhook.objects.create( + source="zammad", + event="", + meta={}, + content={ + "ticket": { + "id": 123, + "group": {"id": "123", "name": "TestZammad Helpdesk"}, + "updated_by": {"firstname": "Cookie", "lastname": "Monster"}, + "title": "Test Ticket Title", + "owner": {"firstname": "Kermit", "lastname": "TheFrog"}, + "state": "open", + "number": "13374321", + "customer": {"firstname": "Cookie", "lastname": "Monster"}, + "created_at": str(timezone.now()), + "updated_at": str(timezone.now()), + "article_ids": [1], + }, + "article": { + "sender": "Customer", + "internal": False, + "ticket_id": 123, + "created_at": str(timezone.now()), + "created_by": {"firstname": "Cookie", "lastname": "Monster"}, + "subject": "New Cookies please", + }, + }, + extra={}, + ) + + process_zammad_webhook(wh) + + dm = DiscordMessage.objects.get() + assert wh.processed_at is not None + assert wh.processed_at < timezone.now() + assert wh.event == "new_ticket_created" + assert dm.channel_id == settings.DISCORD_HELPDESK_CHANNEL_ID + assert dm.channel_name == settings.DISCORD_HELPDESK_CHANNEL_NAME + assert dm.content == ( + "Zammad: " + "TestZammad Helpdesk: Cookie created new ticket " + "https://servicedesk.europython.eu/#ticket/zoom/123" + ) + assert dm.sent_at is None