Skip to main content

Wire protocol (reference)

This is the contract the SDK speaks, transcribed from the running backend. It is protocol version 1 and is tracked by this docs line (/v1/*). Both SDKs implement it identically — you do not need a backend checkout to build against it.

This is the ground truth

Any older aspirational docs (POST /v1/voice/session, session_ready, tool_result, tools_enabled, text_message, open_product) describe a non-running protocol. Do not build against them. If anything disagrees with this page, this page wins.

Two divergence traps (memorize)​

  1. The backend reads user_text, not text_message. It reads action_ack, not tool_call_response. The client-message handler accepts only: ping, hello, mic_state, action_ack, navigation_pending, user_text, cart_event, client_context, end.
  2. UI tool calls are executed server-side and pushed to the client as a fire-and-forget action message; the client replies action_ack. The client does not compute or return a tool result for these — the server already produced the tool result.

1. Auth — session-token issuance​

Each site has one pk_ key: the site's domain admits the website widget, and the app ids you add to it admit your mobile app (Mode B). Mode A signs with the shared secret your backend received when it paired. The SDK never holds the shared secret; it obtains a short-lived session token.

Billing kill-switch: tokens are minted only while provider_connections.status == "connected". Flip the status and every call fails, active sessions are revoked ≤30s.

POST /api/v1/mobile/issue-token
X-Monoverse-Tenant-Id: <uuid>
X-Monoverse-Timestamp: <epoch seconds> # ±300s window
X-Monoverse-Nonce: <single-use, 600s TTL>
X-Monoverse-Signature: <hex>
X-Monoverse-App-Id: <ios bundle id / android package>

{ "lang": "uk" } # optional body
200 { "session_token": "<JWT>", "expires_at": <epoch>, "refresh_after": <epoch>,
"availability": { "voice": true, "chat": true, "recheck_after_seconds": 300 } }

Signature preimage — exact, do not guess:

sig = HMAC_SHA256(secret, "{METHOD}\n{path}\n{timestamp}\n{nonce}\n{sha256_hex(raw_body)}").hex()
# e.g. "POST\n/api/v1/mobile/issue-token\n1718000000\n<nonce>\n<sha256hex(body)>"
# body_sha256 = sha256(raw_request_body_bytes).hexdigest() (empty body → sha256(b"") hex)

Mode B — publishable key​

POST /api/v1/mobile/issue-token-public
{ "api_key": "pk_…", "app_id": "<bundle/package>", "attestation": "<optional>", "lang": "uk" }
200 { "session_token": "<JWT>", "expires_at": <epoch>, "refresh_after": <epoch>, "availability": { … } }
401 publishable_key_invalid · connection_inactive
403 app_id_not_allowed

The session token​

HS256 JWT, claims { iss, aud, iat, exp(~3600s), tenant_id, shop_id, app_id, language, channel:"mobile", allowed_app_ids:[…] } — allowed_app_ids replaces the web token's allowed_origins. TTL 3600 / refresh-after 1800. Store in Keychain / EncryptedSharedPreferences; never log. The SDK re-issues before refresh_after.

Availability​

Both token responses carry availability, null when the key's connection has no site (then treat the entry point as available). Hide the entry point while the variant is false, and re-read it after recheck_after_seconds:

GET /api/v1/mobile/availability
Authorization: Bearer <session_token>
X-Monoverse-App-Id: <ios bundle id / android package>
200 { "availability": { "voice": true, "chat": false, "recheck_after_seconds": 120 } }
401 mobile_token_invalid · connection_inactive
403 app_id_not_allowed
429 availability_rate_limited # 60 reads a minute per connection

Full narrative with SDK snippets: Auth & API keys.

2. WebSocket open​

GET wss://<host>/api/v1/widget/ws?tenant_token=<session_token>&conversation_id=<optional>&lang=<optional>&protocol=1

The WS endpoint is shared with the web widget; the backend branches on channel == "mobile" to skip the origin check and assert app_id.

Fatal close codes — do NOT reconnect:

CodeMeaning
4400malformed, or a protocol 2 socket with a credential in its URL (credentials_in_query)
4401invalid/expired token (or key blocked), or a protocol 2 socket without a valid auth frame (auth_frame_invalid)
4403app-id not allowed
4426protocol version outside the server's window (§11)
4503voice provider down
1008session limit
1011server crash

All other drops → reconnect (backoff), capped at ≤3 attempts.

Protocol 2 — credentials in the first frame​

The web widget speaks protocol 2: its socket URL carries no credential, and the session token and the resume token travel in the first frame the client sends after open.

GET wss://<host>/api/v1/widget/ws?conversation_id=<optional>&lang=<optional>&protocol=2
{ "type": "auth", "tenant_token": "<session_token>", "resume_token": "<optional>", "visitor_pass": "<optional>" }
  • The server accepts the socket, then reads this frame before any other check, with a 5-second deadline.
  • tenant_token is 8 to 4096 characters, resume_token at most 256, visitor_pass at most 128; any other field, type or shape is refused.
  • visitor_pass is the pass the last POST /api/v1/widget/public-token answer carried. It proves the URL's visitor_id only when it was minted for that id and that shop; an absent or foreign pass refuses nothing, and the session then reads no buyer memory.
  • A silent socket, a non-JSON or binary frame, another type or a bad shape closes 4401 auth_frame_invalid.
  • A tenant_token or resume_token in the URL of a protocol 2 socket closes 4400 credentials_in_query.
  • Every later frame, hello first, follows the auth frame; a reconnect sends it again.
  • Protocol 1, with both credentials in the URL, stays accepted for telephony, the mobile SDKs and cached widget bundles until MIN rises under the bump policy (§11).

3. Handshake (server → client, immediately on open)​

{ "type": "ready", "conversation_id": "…", "language": "uk", "issued_at": 1718000000 }
{
"type": "session_state",
"state": {
"conversation_id": "…",
"session_id": "…",
"language": "uk",
"bot_state": "…",
"voice_enabled": true,
"reconnected_via_resume": false
}
}
No voice_config message

There is no voice_config on this path. Hardcode the sample rates: uplink 16000 Hz, downlink 24000 Hz.

Raw binary WS frames (no JSON envelope). The server reads the bytes and forwards them to speech recognition as audio/pcm;rate=16000.

  • Format: PCM16, mono, signed little-endian, 16000 Hz.
  • Frame size: 20–40 ms recommended. 20 ms = 640 bytes, 40 ms = 1280 bytes. The backend is frame-size agnostic.

5. Text turn (client → server)​

{ "type": "user_text", "text": "…" }

(Not text_message.)

  • Binary frames = assistant audio, PCM16 mono 24000 Hz LE. Decode Int16 → float for playback.
  • { "type": "transcript", "role": "user" | "model", "text": "…", "partial": true }
  • { "type": "turn_complete" }
  • { "type": "barge_in" } → flush the playback buffer immediately.
  • { "type": "tool_call", "tool_call_id": "…", "name": "…", "args": {…} } → informational ("the bot is doing something"); show it in the UI.
  • { "type": "action", "action_id": "…", "action": "…", "params": {…}, "context": {…}, "issued_at": …, "timeout_ms": … } → the actionable UI command (navigate / open_product / add_to_cart / apply_filter / …). Run the registered handler or fire the deep link, then reply action_ack (§7).
  • Also: session_state, admission_refused, error, navigation_pause_acknowledged, hello_ack, pong.

7. Client control / ack / context (client → server)​

  • { "type": "action_ack", "action_id": "…", "ok": true, "result": {…} } — confirm a UI action ran.
  • { "type": "ping", "ts": <ms> } → server { "type": "pong", "ts": … }. Heartbeat ~every 25s; if no pong in ~30s, close 4000 and reconnect.
  • { "type": "hello", "protocol_version": 1, "sdk_version": "…", "is_leader": true, "capabilities": {…} } → hello_ack.
  • { "type": "mic_state", "state": "granted" | "denied" | … }.
  • { "type": "client_context", "page_context": {…}, "discovered_urls": [...] } — app-side context (§10).
  • { "type": "cart_event", … } — cart snapshot / changes (§10).
  • { "type": "end", "reason": "user_closed" } → real termination. Send only on explicit close (X) / endSession(), never on minimize.

8. Close & reconnect (the minimize ≠ close contract)​

  • WS drop (network blip, app backgrounded, minimize-that-drops-socket) → the backend keeps Redis state alive 60s. Reconnect to the same conversation_id within 60s → the server resumes the voice session. Outside 60s → fresh session, prior context recapped from DB. This resume/recap holds for the web and telephony channels only. On mobile a reconnect always starts a fresh guest session — the server binds a mobile session to the merchant, not the individual shopper, so it neither resumes the prior session nor recaps prior context, even within 60s with the same conversation_id. Per-subject mobile continuity is not currently scheduled.
  • minimize() = UI-only. Keep the WS open (preferred) or let it drop and rely on the 60s reattach (on mobile a dropped socket reconnects into a fresh guest session — no reattach — see above). Never send end.
  • endSession() = send { "type": "end", "reason": "user_closed" }, then tear down mic/playback/WS.
  • Bot-initiated end = server sends a terminal session_state + closes; emit ended, tear down.

See Lifecycle for the SDK-level view.

9. Tool action handling (DOM-less mobile profile)​

Server-side local tools (search_catalog, get_product, find_similar_products, compare_products, list_subcategories, list_top_categories, site-nav resolution, end_session) are unchanged — the bot speaks the results; the client does nothing.

For action messages (client-executed tools), map each to a merchant handler / deep link, then action_ack:

actionMobile mapping
open_product / navigate / open_category / view_cart / open_checkoutdeep link → merchant route; fallback native callback
add_to_cart / remove_from_cart / update_cart_qtynative callback (merchant cart API); no handler → { ok: false, error: "no_handler" }
apply_filter / filter_by_attribute / clear_filternative callback (merchant list)
highlight / scroll_tonative callback or no-op ok: true if the list is not addressable
show_toastnative callback (snackbar)
set_delivery_method / set_payment_method / update_order_note / confirm_ordernative callback if implemented, else disabled (user_must_confirm)
submit_formserver-side plugin callback unchanged, or native override
open_popup / switch_languagenative callback or disabled

Unregistered tool → the SDK auto-replies { success: false, error: "no_handler" } without crashing. The bot adapts. SDK-level guide: Tool handlers & deep links.

10. Context enrichment (app → bot)​

The backend gets catalog data from the merchant's e-com backend (ingest), but the app can supplement it with live client-side context. This reuses existing backend frames — no backend change:

  • client_context — sent on session start and on screen changes via updateContext({…}). Carries an AppContext: current screen/route, current product id, viewed category, locale, auth state (a loggedIn boolean, not PII), and arbitrary merchant custom key/values. Zero PII.
  • cart_event — sendCartEvent({…}): cart snapshot + add/remove/qty changes, so the bot knows the cart without a round-trip.
  • hello.capabilities — declare { voice, text, native_audio, handlers: [registered tool names] } so the bot only offers tools the app can actually execute.

Keep all of it PII-free (zero-PII guarantee). SDK-level guide: Context enrichment.

11. Version windows​

The server accepts a window of protocol versions, MIN..MAX, rather than one exact number — for this socket and for the plugin sync protocol alike.

ProtocolVersion travels inWindowOutside the window
Widget / SDK socketthe protocol query parameter of the WebSocket open1..2accepted, then closed with 4426 protocol_unsupported
Plugin syncthe X-Monoverse-Protocol-Version request header2..2HTTP 426 protocol_upgrade_required
  • A socket opened without protocol counts as version 1, because the mobile SDKs and older embeds omit it, for as long as MIN is 1.
  • 4426 is fatal: retrying sends the same version, so do not reconnect.
  • Every successful sync response carries X-Monoverse-Protocol-Supported: <MIN>-<MAX>; one on a version below MAX also carries X-Monoverse-Protocol-Deprecated: <MAX>. Upgrade before MIN rises.
  • The sync 426 carries the same X-Monoverse-Protocol-Supported header, and its body names the window as "supported": { "min": <MIN>, "max": <MAX> } beside "expected_version", which is MAX.

Bump policy. A bump ships with MIN = N and MAX = N + 1. MIN rises no earlier than 90 days later, and only once voicebot_sync_protocol_requests_total shows under 1% of requests on N for 14 days.

12. Widget delivery: versions and the latest channel​

Every widget build is published twice under https://api.monoverse.tech/widget/.

PathHoldsCache-Control
/widget/v/<id>/one build, never changed after its deploypublic, max-age=31536000, immutable
/widget/the build the latest channel serves nowpublic, max-age=300, must-revalidate
/widget/latest.jsonwhich build that ispublic, max-age=300, must-revalidate
  • <id> is the first 12 hex digits of the commit the build came from. A version directory holds the bundles, its own pcm-worklet-processor.js and a version.json carrying id, widget_version and git_sha.
  • latest.json carries the same three fields plus deployed_at, the UTC time the channel last moved.
  • Latest is the default. An unpinned site picks up a release, or a rollback, within five minutes.
  • Pinning holds a site on one build. Load /widget/v/<id>/widget-voice.js and set data-worklet-url to /widget/v/<id>/pcm-worklet-processor.js: without it the widget loads the worklet beside data-cdn, which defaults to the API host and so to the latest build. The WordPress plugin sets both from one address, its MONOVERSE_SYNC_WIDGET_URL constant or its widget URL setting.
  • Retention. Each deploy keeps the 20 most recent versions and the one latest.json names. An older pinned <id> answers 404, so move a pin forward before 20 newer deploys pass it.
  • Rollback. An operator points the latest channel at any kept version without a rebuild, and latest.json then names it.