Overview
The widget communicates with your application through six callback functions passed in the config. These callbacks let you synchronize your store’s cart, track analytics, and handle errors.onCartChanged
Fired when the AI assistant adds, removes, updates, or clears items in the cart via webhooks. Use this callback to update your store’s cart UI in real time.CartChangedEvent
CartItem
Example: Sync with store cart
The
onCartChanged callback is a UI notification only. The actual cart change has already been confirmed via the server-to-server webhook to your backend. This callback is for updating the client-side UI.onProductClick
Fired when a user clicks the “Add” button on a product card within the chat. This callback is informational — the cart update itself is handled byonCartChanged after the server confirms the webhook.
ProductItem
Example: Track product interactions
onSessionComplete
Fired when the server sends a response with a session summary attached. This provides the current state of all items the user has selected during the conversation.SessionSummary
Example: Update checkout state
onSessionComplete is also called when a session is restored on reconnect, providing the previously selected items.onError
Fired on any error, whether from the server (rate limits, internal errors) or from the client (connection failures, message too large).WidgetError
Server Error Codes
rate_limit_exceeded, user_message_limit, user_conversation_limit, tenant_daily_token_limit, tenant_monthly_token_limit, agent_busy, message_too_large, invalid_json, internal_error, max_rounds_exceeded, session_token_limit, no_catalog_data
Client Error Codes
auth_error, auth_timeout, ws_error, message_too_large, queue_full, max_reconnect, connection_lost
Example: Error logging
onConnect
Fired when the WebSocket connection is authenticated and ready to send/receive messages. This is called after theauth_ok message is received from the server.