What You Need to Build
To integrate VIZOCHOK into a mobile app, you need to implement:WebSocket Client
Connect to
wss://api.vizochok.com/api/v1/ws/chat, handle authentication, send/receive JSON messages, manage reconnection.Chat UI
Text input, message bubbles, streaming text display (token-by-token), typing indicators.
Product Cards
Render
product_cards messages as native product list with images, prices, quantity steppers, and “Add” buttons.Cart Sync
Listen for
cart_changed events and update your app’s cart state. Send action messages when user interacts with product cards.WebSocket Message Types to Handle
Your mobile client needs to handle these server messages:| Message Type | Purpose | UI Action |
|---|---|---|
auth_ok | Authentication confirmed | Enable chat input |
conversation_started | New conversation created | Save conversation_id |
session_restored | Reconnected to existing session | Restore cart state |
text_delta | Streaming text chunk | Append to current message bubble |
text_end | Text block complete | Stop streaming indicator |
status | Progress update (e.g. “Searching…”) | Show status indicator |
product_cards | Product results | Render native product list |
quick_replies | Suggestion buttons | Show tappable option pills |
cart_changed | Cart was modified | Update cart badge/state |
ingredient_checklist | Recipe ingredients | Render checkable list |
error | Error occurred | Show error message |
response_complete | Ready for next message | Enable input |
| Message Type | When |
|---|---|
auth | First message after connection |
message | User sends text |
action | User taps product card, quick reply, or checklist submit |
ping | Every 30 seconds (keepalive) |
pong | In response to server ping |
Platform-Specific Considerations
React Native
- Use a WebSocket library (built-in
WebSocketAPI orreact-native-websocket) - Handle
AppStatechanges: disconnect on background, reconnect on foreground - Store
conversation_idinAsyncStoragefor session persistence - Use
FlatListfor message rendering with streaming text support
Flutter
- Use
web_socket_channelpackage for WebSocket connection - Listen to
AppLifecycleStatefor background/foreground transitions - Store
conversation_idinshared_preferences - Use
StreamBuilderto render incoming messages reactively
Native iOS / Android
- iOS:
URLSessionWebSocketTask(iOS 13+) or Starscream - Android: OkHttp WebSocket or Java-WebSocket
- Both: handle network reachability changes, reconnect with exponential backoff
Connection Lifecycle for Mobile
User sends a message
Send
message with text and conversation_id. Show streaming response as text_delta messages arrive.User interacts with products
When user taps “Add” on a product card, send
action message with sku and quantity. Listen for cart_changed to confirm.Reconnection Strategy
Implement exponential backoff with jitter, matching the web SDK behavior:| Parameter | Value |
|---|---|
| Initial delay | 1,000 ms |
| Max delay | 10,000 ms |
| Formula | min(1000 * 2^attempt, 10000) |
| Jitter | +/- 25% |
| Max attempts | 30 |
4001, 4002, 4003, 4004).