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.
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)
- The backend reads
user_text, nottext_message. It readsaction_ack, nottool_call_response. The client-message handler accepts only:ping,hello,mic_state,action_ack,navigation_pending,user_text,cart_event,client_context,end. - UI tool calls are executed server-side and pushed to the client as a fire-and-forget
actionmessage; the client repliesaction_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.
Mode A — server-minted (recommended)
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:
| Code | Meaning |
|---|---|
4400 | malformed, or a protocol 2 socket with a credential in its URL (credentials_in_query) |
4401 | invalid/expired token (or key blocked), or a protocol 2 socket without a valid auth frame (auth_frame_invalid) |
4403 | app-id not allowed |
4426 | protocol version outside the server's window (§11) |
4503 | voice provider down |
1008 | session limit |
1011 | server 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_tokenis 8 to 4096 characters,resume_tokenat most 256,visitor_passat most 128; any other field, type or shape is refused.visitor_passis the pass the lastPOST /api/v1/widget/public-tokenanswer carried. It proves the URL'svisitor_idonly 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
4401auth_frame_invalid. - A
tenant_tokenorresume_tokenin the URL of a protocol 2 socket closes4400credentials_in_query. - Every later frame,
hellofirst, 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
MINrises 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
}
}
voice_config messageThere is no voice_config on this path. Hardcode the sample rates: uplink 16000 Hz, downlink
24000 Hz.
4. Audio uplink (client → server)
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.)
6. Downlink (server → client)
- 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 replyaction_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, close4000and 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_idwithin 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 sameconversation_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 sendend.endSession()= send{ "type": "end", "reason": "user_closed" }, then tear down mic/playback/WS.- Bot-initiated end = server sends a terminal
session_state+ closes; emitended, 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:
action | Mobile mapping |
|---|---|
open_product / navigate / open_category / view_cart / open_checkout | deep link → merchant route; fallback native callback |
add_to_cart / remove_from_cart / update_cart_qty | native callback (merchant cart API); no handler → { ok: false, error: "no_handler" } |
apply_filter / filter_by_attribute / clear_filter | native callback (merchant list) |
highlight / scroll_to | native callback or no-op ok: true if the list is not addressable |
show_toast | native callback (snackbar) |
set_delivery_method / set_payment_method / update_order_note / confirm_order | native callback if implemented, else disabled (user_must_confirm) |
submit_form | server-side plugin callback unchanged, or native override |
open_popup / switch_language | native 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 viaupdateContext({…}). Carries anAppContext: current screen/route, current product id, viewed category, locale, auth state (aloggedInboolean, not PII), and arbitrary merchantcustomkey/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.
| Protocol | Version travels in | Window | Outside the window |
|---|---|---|---|
| Widget / SDK socket | the protocol query parameter of the WebSocket open | 1..2 | accepted, then closed with 4426 protocol_unsupported |
| Plugin sync | the X-Monoverse-Protocol-Version request header | 2..2 | HTTP 426 protocol_upgrade_required |
- A socket opened without
protocolcounts as version1, because the mobile SDKs and older embeds omit it, for as long asMINis1. 4426is 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 belowMAXalso carriesX-Monoverse-Protocol-Deprecated: <MAX>. Upgrade beforeMINrises. - The sync
426carries the sameX-Monoverse-Protocol-Supportedheader, and its body names the window as"supported": { "min": <MIN>, "max": <MAX> }beside"expected_version", which isMAX.
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/.
| Path | Holds | Cache-Control |
|---|---|---|
/widget/v/<id>/ | one build, never changed after its deploy | public, max-age=31536000, immutable |
/widget/ | the build the latest channel serves now | public, max-age=300, must-revalidate |
/widget/latest.json | which build that is | public, 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 ownpcm-worklet-processor.jsand aversion.jsoncarryingid,widget_versionandgit_sha.latest.jsoncarries the same three fields plusdeployed_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.jsand setdata-worklet-urlto/widget/v/<id>/pcm-worklet-processor.js: without it the widget loads the worklet besidedata-cdn, which defaults to the API host and so to the latest build. The WordPress plugin sets both from one address, itsMONOVERSE_SYNC_WIDGET_URLconstant or its widget URL setting. - Retention. Each deploy keeps the 20 most recent versions and the one
latest.jsonnames. An older pinned<id>answers404, 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.jsonthen names it.