Skip to content

feat(webhooks): send live chat events to webhook subscribers - #110

Merged
mpge merged 1 commit into
mainfrom
feat/chat-webhooks
Oct 23, 2026
Merged

mpge merged 1 commit into
mainfrom
feat/chat-webhooks

Conversation

@mpge

@mpge mpge commented Oct 23, 2026

Copy link
Copy Markdown
Member

Webhooks did not send the live chat events chat.started, chat.assigned, chat.message and chat.ended; only workflows ran on them (chat.transferred was added in #109). This sends them to subscribed webhooks with escalated-laravel's DispatchWebhook chat payloads and offers them in the webhook event list.

Changes

  • EventVocabulary::WEBHOOK_EVENTS gains the four events (Laravel's order), so the webhook form offers them.
  • NotificationService listens on escalated_chat_started, escalated_chat_accepted, escalated_chat_message, escalated_chat_ended; one dispatch_chat_event() builds the payload for all five chat events: the ticket plus chat {session_id, ticket_id, status, agent_id, department_id}, with from/to_* for transferred, reply_id + author_type for message (no body), ended_by for ended. Visitor email and chat token never leave.
  • escalated_chat_message passes $author_type as a third argument; ChatSessionService::end() takes an optional $ended_by (default system) passed as the third argument of escalated_chat_ended. Agent end endpoint passes agent, widget end endpoints customer, idle cleanup stays system (Laravel's values).
  • WorkflowListener registrations widened to match (Test_Hook_Signatures).
  • docs/webhooks.md and CHANGELOG [Unreleased]. Existing webhooks are not subscribed automatically.

Tests

tests/Test_Chat_Webhooks.php drives the real REST routes (widget /chat/start, /chat/{id}/messages, /chat/{id}/end; agent /chat/{id}/accept, /messages, /end with an API token) and the cleanup cron, and checks delivered webhook bodies: event names, chat fields, author_type, ended_by, no email/token/body leakage, and no chat events for a webhook not subscribed to them. Failed before the change (5/6), passes after. Full suite locally: 923 tests, only the known environment-dependent Test_Ticket_Access_Migration separate-database case fails locally (same as on main). Pint clean.

Not covered: Laravel also raises chat.assigned when routing assigns an agent at chat start; here a chat routed at start fires only chat.started (workflows behave the same way today).

…at.ended

Webhook subscribers now receive the live chat events that only workflows
got before, with escalated-laravel's DispatchWebhook chat fields. The
webhook form offers them. chat.message carries reply_id and author_type,
never the body; chat.ended carries ended_by (agent, customer or system).
@mpge
mpge merged commit da37fed into main Oct 23, 2026
3 checks passed
@mpge mpge mentioned this pull request Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant