#16063·chatwoot

Webhooks: expose message status in message_created / message_updated payloads

Author: GabrielgvlCreated Sep 29, 2026Updated Sep 29, 2026

Is your feature or enhancement related to a problem? Please describe.

We run a self-hosted Chatwoot CE (v4.18.0) integration that consumes account webhooks to track outbound delivery state (sent → delivered/read/failed) for transactional messages sent through the API.

message_updated fires on every persisted status change, but the payload root — Message#webhook_data — exposes id, message_type, private, source_id, content_attributes, etc., and no status. The only in-band carrier is conversation.messages[0].status, the latest public-chat message snapshot, which describes the updated message only while that message still happens to be the conversation's last public chat message. Any newer incoming message or reply removes the status of the message the event is actually about, so consumers cannot reliably observe per-message delivery state from the signed payload. conversation.status is the conversation lifecycle, not per-message delivery state. push_event_data (the ActionCable payload) already includes status, so its absence on the webhook side looks accidental rather than designed.

Describe the solution you'd like

Add status to Message#webhook_data (app/models/message.rb), serialized as the enum name string — sent, delivered, read, failed — the same way message_type already serializes its enum. This is one additive line and appears on both message_created (initial sent) and message_updated (post-commit status) roots; the existing HMAC signature covers the new field automatically, and JSON consumers that ignore unknown keys are unaffected.

Spec expectations:

  • spec/models/message_spec.rb (webhook_data context): assert webhook_data[:status] equals the message's status string.
  • spec/listeners/webhook_listener_spec.rb: a #message_updated example where a status change enqueues a webhook whose payload carries the updated message's own id and status.

Prior art: PR #15908 already implements this (and additionally adds changed_attributes to message_updated). If the maintainers prefer the smallest additive surface, the status-only subset is a one-line diff — we are happy to contribute that narrower PR if it helps review.

Describe alternatives you've considered

  • Correlate conversation.messages[0] when nested.id == root.id: works only while the updated message remains the last public-chat message — partial coverage by construction (and PR #15602 shows the nested snapshot can carry the wrong message entirely).
  • Infer state from source_id becoming non-null: misses delivered/read/failed transitions.
  • Consume changed_attributes: not present on message events today (also covered by #15908).
  • Subscribe to the channel provider's webhooks directly: a much larger separate integration that duplicates what Chatwoot already normalizes internally.

Additional context

Verified at tag v4.18.0 (commit 9f920b549c14491a4e587687a3eed5d21c6ccc7d): webhook_data emits account, additional_attributes, content_attributes, content_type, content, conversation, created_at, id, inbox, message_type, private, sender, source_id (+ conditional attachments). Enum at message.rb: status: { sent: 0, delivered: 1, read: 2, failed: 3 }. Additive, non-breaking; payload grows ~10–20 bytes.

Example message_updated root after this change:

json
{
  "event": "message_updated",
  "id": 12345,
  "status": "delivered",
  "message_type": "outgoing"
}