Conversation and inbox webhook payloads now include the account object
(`{ id, name }`) so integrations can reliably identify the account
without depending on nested message data.
## Closes
Closes #11753
Closes #12442
## Why
Message, contact, and contact inbox webhook payloads already expose
`account`. Conversation and inbox webhook payloads were outliers, which
forced webhook consumers to infer account context from nested messages
or other fields that may not always be present.
## What changed
- Adds `account: { id, name }` to conversation webhook payloads.
- Adds webhook-specific inbox payload data with `account: { id, name }`
for inbox created/updated events.
- Keeps non-webhook conversation and inbox push payload behavior
unchanged.
## How to test
- Configure an account webhook for `conversation_created`, trigger a new
conversation, and confirm the webhook payload includes `account.id` and
`account.name`.
- Configure an account webhook for `inbox_created`, create a new inbox,
and confirm the webhook payload includes `account.id` and
`account.name`.
- Configure a webhook agent bot and update a conversation status, then
confirm the bot webhook payload includes the same account object.
---------
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Sojan Jose <sojan@pepalo.com>
64 lines
1.7 KiB
Ruby
64 lines
1.7 KiB
Ruby
class Conversations::EventDataPresenter < SimpleDelegator
|
|
def push_data
|
|
{
|
|
additional_attributes: additional_attributes,
|
|
can_reply: can_reply?,
|
|
channel: inbox.try(:channel_type),
|
|
contact_inbox: contact_inbox,
|
|
id: display_id,
|
|
inbox_id: inbox_id,
|
|
messages: push_messages,
|
|
labels: label_list,
|
|
meta: push_meta,
|
|
status: status,
|
|
custom_attributes: custom_attributes,
|
|
snoozed_until: snoozed_until,
|
|
unread_count: unread_incoming_messages.count,
|
|
first_reply_created_at: first_reply_created_at,
|
|
priority: priority,
|
|
waiting_since: waiting_since.to_i,
|
|
**push_timestamps
|
|
}
|
|
end
|
|
|
|
# Like #push_data but with message text normalized for external integrations (webhooks).
|
|
def webhook_data
|
|
push_data.merge(
|
|
account: account.webhook_data,
|
|
messages: webhook_push_messages
|
|
)
|
|
end
|
|
|
|
private
|
|
|
|
def push_messages
|
|
[messages.where(account_id: account_id).chat.last&.push_event_data].compact
|
|
end
|
|
|
|
def webhook_push_messages
|
|
[messages.where(account_id: account_id).chat.last&.webhook_push_event_data].compact
|
|
end
|
|
|
|
def push_meta
|
|
{
|
|
sender: contact.push_event_data,
|
|
assignee: assigned_entity&.push_event_data,
|
|
assignee_type: assignee_type,
|
|
team: team&.push_event_data,
|
|
hmac_verified: contact_inbox&.hmac_verified
|
|
}
|
|
end
|
|
|
|
def push_timestamps
|
|
{
|
|
agent_last_seen_at: agent_last_seen_at.to_i,
|
|
contact_last_seen_at: contact_last_seen_at.to_i,
|
|
last_activity_at: last_activity_at.to_i,
|
|
timestamp: last_activity_at.to_i,
|
|
created_at: created_at.to_i,
|
|
updated_at: updated_at.to_f
|
|
}
|
|
end
|
|
end
|
|
Conversations::EventDataPresenter.prepend_mod_with('Conversations::EventDataPresenter')
|