Architecture
There are three participants in the cart flow:SDK Widget
Receives
cart_changed events via WebSocket to update the UI. Never talks to your backend directly for cart operations.VIZOCHOK Backend
AI Agent decides what to add/remove. Calls your webhooks server-to-server for validation.
Your Backend
Source of truth for cart state. Validates operations, checks stock, persists the real cart.
Cart Operation Flow
1
Customer requests cart action
Customer says “Add this milk to my cart” in the chat.
2
AI Agent calls your cart webhook
The agent calls
add_to_selection(sku="milk-001", qty=1) which sends a POST to your cart_url:3
Your backend confirms or rejects
Success:
{"ok": true}Failure: {"ok": false, "reason": "out_of_stock"}4
Agent updates state and responds
Agent updates internal cart state, generates a confirmation message, and sends via WebSocket:
text_delta/text_end(AI message)event {type: "item_selected", sku, name, ...}cart_changed {action, items[], total}
5
SDK fires onCartChanged callback
Your frontend receives the
onCartChanged(cart) callback and updates the cart badge/sidebar.Initial Cart Loading
1
New WebSocket connection
Customer opens the chat widget and connects via WebSocket.
2
VIZOCHOK calls your cart GET webhook
3
Your backend returns current cart
4
AI starts with context
The AI agent starts the conversation knowing the customer already has bread and butter in their cart.
The
session_id parameter matches the userId you pass to the SDK widget config, or an auto-generated identifier if userId is not provided. Use this to look up the correct cart on your side.Handling Cart Events in Your Frontend
Register theonCartChanged callback in the widget config to keep your cart UI in sync with AI-managed changes. For the full callback API, event types, and integration examples, see Events & Callbacks.
CartItem Structure
Each item incart.items contains:
Handling Rejections
When your backend rejects a cart operation (e.g., product is out of stock), the AI handles it gracefully:1
AI initiates cart action
AI: “I’ll add that milk to your cart.”
2
Your webhook rejects
Your backend returns:
{"ok": false, "reason": "out_of_stock"}3
AI suggests alternatives
AI: “Sorry, that milk is currently out of stock. Would you like to try a different brand?”
The AI will suggest alternatives when a product is unavailable, using the same search and recommendation system.
Cart Operations
The AI can perform four cart operations through your webhook:
For the complete webhook request/response specification, see Cart Webhook.
Without Webhooks
If you do not configure cart webhooks, VIZOCHOK still tracks the cart internally during the conversation. However:- Cart state is session-only (not persisted to your backend)
- No stock validation on add
- The
onCartChangedevent still fires in the SDK - Your frontend would need to reconcile the AI cart with your real cart