MobiariDocs

Realtime inbox

The two WebSockets behind the shared inbox and the storefront chat. The chat widget socket, every event, heartbeats, reconnects and how to catch up over REST.

The team inbox is not public yet

Conversations are not part of the public API yet: the team side of the inbox (the agent socket, listing conversations, replying) will be documented here when it is. The chat widget socket and the /widget/... calls below work as described.

The shared inbox (WhatsApp, e-mail and storefront chat) pushes changes over WebSockets. There are two sockets:

SocketWho connectsScope
/ws/conversationsTeam members: the admin and the mobile appsEvery conversation of one store
/ws/widgetA shopper's browser (the chat widget)One conversation

The sockets only tell you that something changed. Reading and writing go over REST.

The widget socket answers at the root and under /v1:

wss://api.mobiari.com/v1/ws/widget

All frames are JSON text frames.

Agent socket: /ws/conversations

The team's socket carries every conversation of one store. Connecting to it is not part of the public API yet; this section describes the events it carries, which are the ones the Mobiari admin and apps react to.

Events from the server

Every event has the same envelope:

{
  "type": "message:new",
  "store_id": "0199a0c4-...",
  "conversation_id": "0199b1d2-...",
  "audience": "all",
  "data": { },
  "origin": "0199a000-..."
}

audience and origin are internal routing details; ignore them. Event types (more may be added: ignore unknown ones):

typedataWhen
conversation:newa ConversationListItem (an inbox row: the Conversation plus display_name, assignee_name, customer_name, waiting_since)A new conversation got its first message. Sent once, just before that message's message:new, so last_message_preview and display_name are already filled
conversation:updateda ConversationStatus, assignee, unread counts, labels, last message... changed
message:newa ConversationMessageAny message: contact, team, bot or system line
message:updateda ConversationMessageDelivery status changed (sent → delivered → read, or failed)
messages:read{ "conversation_id", "by": "visitor" }The shopper read the team's messages (web chat)
note:newa ConversationNoteSomeone added an internal note
cart:updated{ "conversation_id", "cart": ConversationCart | null }The assisted-sale cart changed (null: detached)
typing{ "conversation_id", "from": "visitor" | "agent", "user_id"?, "typing": bool }Someone is typing. Clear the indicator after about 6 seconds without a repeat
viewing{ "conversation_id" | null, "user_id", "user_name", "viewing": bool }A team member opened (or left) a conversation
presence{ "online": [user_id, ...] } or { "conversation_id", "visitor_online": bool }Team members connected to the inbox; the shopper's chat opened or closed
resyncnoneThe client fell behind and missed events: it must refetch
pongnoneAnswer to a ping

conversation:new carries a whole inbox row: insert it into the list as is. A conversation that never gets a message (a web chat opened and left without writing) sends no conversation:new. conversation:updated carries the bare Conversation, without the list row's display_name, assignee_name and waiting_since: merge it into the row you have, or refetch the row.

Example message:updated after WhatsApp reports the message read:

{
  "type": "message:updated",
  "conversation_id": "0199b1d2-...",
  "data": { "id": "0199b1e0-...", "sender": "agent", "delivery_status": "read", "read_at": "2026-09-26T14:05:40Z", "...": "..." }
}

Visitor socket: /ws/widget

The chat widget opens it once the shopper has a conversation, with the channel key, the conversation id and the visitor token from POST /widget/{key}/conversations:

wss://api.mobiari.com/v1/ws/widget?key=ch_3b1f...&conversation_id=0199b1d2-...&token=8f8b...

The token can also go in an X-Visitor-Token header instead of the query. The channel's allowed origins apply. The handshake answers 404 (unknown key or conversation), 403 (disabled channel or origin not allowed) or 401 (bad token).

The server sends the conversation's events, without internal ones (notes, presence, viewing):

{ "type": "message:new", "conversation_id": "0199b1d2-...", "data": { "id": "...", "sender": "agent", "text": "Oi!", "payload": {}, "...": "..." } }
typedata
message:new, message:updatedthe message
conversation:updated{ "status", "bot_active", "assignee_user_id", "unread_for_visitor" } only
cart:updated{ "conversation_id", "cart" }
typing{ "conversation_id", "from", "typing" } (show it when from is not visitor)
resyncnone: reload the messages
pongnone

The widget may send { "type": "typing", "typing": true } and { "type": "ping" }.

Heartbeats and keep-alive

  • The server sends a WebSocket ping frame every 30 seconds. Browsers, URLSessionWebSocketTask and OkHttp answer with a pong automatically.
  • The server closes a connection it has heard nothing from (no frame, pongs included) for 75 seconds.
  • Clients should also send { "type": "ping" } every 25 seconds and treat a missing pong within 10 seconds as a dead connection. Proxies and mobile networks drop idle TCP connections silently; this is how you notice.

Reconnecting

Reconnect whenever the socket closes, with exponential backoff and jitter: 1 s, 2 s, 4 s ... up to 30 s, reset after a connection that lasted. A handshake refused with 401, 403 or 404 is not transient: stop.

Events are not replayed. Whatever happened while the widget was disconnected (or when the server sends resync) you fetch over REST, with the same key and visitor token:

  1. The messages. GET /widget/{key}/conversations/{conversation_id}/messages answers the latest 200 messages, oldest first.
  2. The conversation. GET /widget/{key}/conversations/{conversation_id}.

Deduplicate by id everywhere: an event can arrive while the REST call that covers it is in flight.

Sending and the WhatsApp 24-hour window

Messages go over REST, not the socket. The shopper's messages are sent with POST /widget/{key}/conversations/{conversation_id}/messages (at most 20 a minute per conversation). Send an Idempotency-Key with every message so a retry after a lost response does not send it twice.

On the team's side, WhatsApp only accepts free-form messages within 24 hours of the contact's last message. Outside that window a reply is refused with status 422 and code whatsapp_window_closed, and nothing is stored. Sending replies as the team is not part of the public API yet.

On this page