Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions deploy/templates/app/intbot.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion intbot/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
51 changes: 50 additions & 1 deletion intbot/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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