@vizochok/widget) that embeds an AI-powered shopping assistant into any web page. It uses Shadow DOM for style isolation and communicates with the VIZOCHOK backend over WebSocket for real-time streaming.
Prerequisites
- A VIZOCHOK tenant with a public API key (
pk_...) - Your store ID (configured in the admin panel)
Installation
Configuration
TheVIZOCHOKWidget constructor accepts a configuration object with these properties:
| Property | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | Public API key (pk_...) |
storeId | string | required | Store identifier |
userId | string | undefined | Authenticated customer ID for personalization and usage tracking |
language | 'uk' | 'en' | 'ru' | 'uk' | UI language |
apiBase | string | 'https://api.vizochok.com' | API base URL |
position | 'bottom-right' | 'bottom-left' | 'bottom-right' | Widget position on screen |
botName | string | 'Помічник' | Bot display name shown in the chat header |
botAvatar | string | undefined | URL for the bot avatar image |
placeholder | string | undefined | Custom input placeholder text |
welcomeMessage | string | undefined | Welcome message shown when the chat opens |
Theme Options
Customize the widget appearance via thetheme property:
Event Callbacks
Register callbacks to react to widget events:CartChangedEvent
TheonCartChanged callback receives a CartChangedEvent object:
The type of change:
item_selected, item_removed, quantity_updated, or cart_cleared.SKU of the affected product (empty for
cart_cleared).Name of the affected product.
Quantity of the affected product.
Price of the affected product.
Full array of all items currently in the cart. Each item has
sku, name, price, quantity, and optional promo_price and brand.Current cart total.
Framework Examples
Inline Mode
By default, the widget renders as a floating button that opens a chat panel. You can embed it inline within a specific container instead:- The widget fills 100% width and height of the container
- The floating toggle button is hidden
- The chat panel is always open
- You control visibility via the container’s CSS
Switching Modes at Runtime
You can switch between inline and floating mode without losing the conversation:Programmatic Control
The widget instance exposes methods for programmatic control:Shadow DOM & Style Isolation
The widget renders inside a Shadow DOM, which means:- Your page styles do not affect the widget
- The widget styles do not leak into your page
- CSS custom properties are used for theming (set via the
themeconfig)
Because the widget uses Shadow DOM, external CSS frameworks (Bootstrap, Tailwind) will not style the widget’s internals. Use the
theme configuration object instead.Content Security Policy (CSP)
If your site uses a strict Content Security Policy, add these directives:Performance Notes
- Bundle size: The SDK is ~15 KB gzipped with zero external dependencies.
- Lazy connection: The WebSocket connection is established on
mount(), not on instantiation. - Session persistence: Conversation state is saved to
sessionStorageso the user can refresh the page without losing context. - Heartbeat: The widget maintains a heartbeat ping every 30 seconds. If no response is received within 60 seconds, the connection is automatically closed and reconnected.