Files
chatwoot/app/views/api/v1/models/_message.json.jbuilder
T
Muhsin 5ce77eedbe feat(voice): embed Call in voice_call message payload
Adds a nested `call` object to the voice_call message JSON / push
payload so the frontend can read call state directly from message.call
instead of duplicating it in content_attributes.data.

- Message gains has_one :call (inverse of existing Call#belongs_to :message)
  via enterprise module prepend.
- Message serializer (_message.json.jbuilder) emits a call block for
  voice_call messages when the Call is linked.
- Message#push_event_data mirrors the payload into socket broadcasts.
- MessageFinder eager-loads the call (+ contact + inbox.channel) to
  avoid N+1 when listing conversation messages.
- Call gains helper methods: display_status, from_number, to_number,
  recording_url, push_event_data. These centralize the direction- and
  status-aware derivations so jbuilder and push_event_data stay in sync.

Frontend continues to read content_attributes.data — this commit only
adds the new shape; a follow-up swaps readers to message.call.
2026-04-20 13:33:43 +04:00

35 lines
1.3 KiB
Ruby

json.id message.id
json.content message.content
json.inbox_id message.inbox_id
json.echo_id message.echo_id if message.echo_id
json.conversation_id message.conversation.display_id
json.message_type message.message_type_before_type_cast
json.content_type message.content_type
json.status message.status
json.content_attributes message.content_attributes
json.created_at message.created_at.to_i
json.private message.private
json.source_id message.source_id
json.sender message.sender.push_event_data if message.sender
json.attachments message.attachments.map(&:push_event_data) if message.attachments.present?
if message.content_type == 'voice_call' && message.respond_to?(:call) && message.call.present?
call = message.call
json.call do
json.id call.id
json.provider_call_id call.provider_call_id
json.provider call.provider
json.direction call.direction
json.status call.display_status
json.duration_seconds call.duration_seconds
json.conference_sid call.conference_sid
json.accepted_by_agent_id call.accepted_by_agent_id
json.started_at call.started_at&.to_i
json.ended_at call.ended_at
json.from_number call.from_number
json.to_number call.to_number
json.recording_url call.recording_url
json.transcript call.transcript
end
end