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:
| Socket | Who connects | Scope |
|---|---|---|
/ws/conversations | Team members: the admin and the mobile apps | Every conversation of one store |
/ws/widget | A 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/widgetAll 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):
type | data | When |
|---|---|---|
conversation:new | a 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:updated | a Conversation | Status, assignee, unread counts, labels, last message... changed |
message:new | a ConversationMessage | Any message: contact, team, bot or system line |
message:updated | a ConversationMessage | Delivery status changed (sent → delivered → read, or failed) |
messages:read | { "conversation_id", "by": "visitor" } | The shopper read the team's messages (web chat) |
note:new | a ConversationNote | Someone 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 |
resync | none | The client fell behind and missed events: it must refetch |
pong | none | Answer 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": {}, "...": "..." } }type | data |
|---|---|
message:new, message:updated | the 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) |
resync | none: reload the messages |
pong | none |
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,
URLSessionWebSocketTaskand 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 missingpongwithin 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:
- The messages.
GET /widget/{key}/conversations/{conversation_id}/messagesanswers the latest 200 messages, oldest first. - 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.
AI actions
Let the chat AI act in your own system (resend an invoice, restart a deploy, check a subscription) through signed calls to your endpoints.
Push notifications
What the Mobiari mobile apps receive by push. The kinds of notification, what each push carries, where a tap leads, and how operators turn APNs and FCM on.