Widget JS API
Control the widget programmatically — configuration, events, integration, and advanced scenarios.
Quick Start
Paste this code on all pages of your site — before the closing </head> or </body> tag. Replace YOUR_ORG_ID with the ID from the Settings section in your dashboard.
HTML<script>
// Configuration — set before the widget script loads
window.SvyazioConfig = {
orgId: "YOUR_ORG_ID"
};
window.Svyazio = window.Svyazio || function() {
(window.Svyazio.q = window.Svyazio.q || []).push(arguments);
};
</script>
<script async src="https://app.svyazio.ru/widget/svyazio.js"></script>
All Svyazio(...) calls made before the script loads are automatically queued and executed after initialization. The API is safe for asynchronous use.
Configuration
The window.SvyazioConfig object (or alias window.SvyazioSetup) must be set before the script loads. Parameters override settings from the admin panel.
Appearance
| Parameter | Type | Default | Description |
|---|---|---|---|
buttonStyle | 'round' | 'tab' | 'round' | Chat button style. |
buttonPosition | string | 'br' | Button position: bl, bc, br, lt, lm, lb, rt, rm, rb. |
buttonSize | number | 60 | Round button size (px). |
chatWidth | number | 400 | Chat window width (min. 280px). |
chatHeight | number | 600 | Chat window height (min. 300px). |
zIndex | number | 999999 | Widget z-index. |
accentColor | string | from settings | Accent color, e.g. '#6C63FF'. |
colors | object | — | Color scheme (see setColors). |
Behavior
| Parameter | Type | Default | Description |
|---|---|---|---|
startHidden | boolean | false | Hide widget on load. Show it with Svyazio('show'). |
disabledOnMobile | boolean | false | Do not show on mobile devices. |
mobileOnly | boolean | false | Show only on mobile devices. |
disableChatOpenHash | boolean | false | Disable URL hash #svyazioChatExpanded control. |
deferredLoading | boolean | false | Load widget after full page load. |
customWidgetButton | string | — | CSS selector for custom button. Default button is hidden. |
Widget Text
| Parameter | Type | Description |
|---|---|---|
headerText | string | Chat window header title. |
welcomeText | string | Welcome text on first open. |
onlineTitle | string | Subtitle when agents are online. |
offlineTitle | string | Subtitle when agents are offline. |
offlineText | string | Text when no one is online. |
Language & Locale
| Parameter | Type | Description |
|---|---|---|
locale | string | object | Language code ('ru', 'en', 'es', 'pt') or an object with interface string overrides. |
language | string | Alias for locale. |
Visitor Data
| Parameter | Type | Description |
|---|---|---|
clientId | string | Unique user ID from your system — merges history across devices and sessions. |
groupId | string | Department ID for routing conversations (Settings → Departments). |
Callbacks
| Parameter | Type | Description |
|---|---|---|
onNewMessage | function(msg) | On each new message. msg: { id, text, createdAt, type } |
onAnalyticEvent | function(eventName) | On widget analytic events. |
Full configuration example:
JSwindow.SvyazioConfig = {
orgId: "YOUR_ORG_ID",
buttonPosition: "br",
chatWidth: 380,
startHidden: true,
language: "en",
groupId: "abc123",
clientId: "user_42",
headerText: "Support Team",
colors: { buttonBg: "#6C63FF", buttonText: "#fff" },
onNewMessage: function(msg) {
console.log("New:", msg.text, "from", msg.type);
}
};
SvyazioIntegration
An alternative to the setIntegrationData method — pass user data before the widget loads.
HTML<script>
window.SvyazioIntegration = {
name: "John Smith",
email: "john@example.com",
phone: "+1 555 000-0000",
plan: "pro", // custom fields
userId: "12345"
};
</script>
<script async src="https://app.svyazio.ru/widget/svyazio.js"></script>
Open via Link
Add the hash #svyazioChatExpanded to any link — clicking it will automatically open the chat:
HTML<a href="#svyazioChatExpanded">Contact us</a>
<button onclick="location.hash='#svyazioChatExpanded'">Ask a question</button>
The hash is added to the URL when the chat opens, so the Back button closes the chat — just like in native apps.
Visibility & State
Open the chat window. true — focus the input field.
JSSvyazio('openChat');
Svyazio('openChat', true); // with focus
Similar to openChat, but ignores mobile calls. Useful for desktop triggers.
JSSvyazio('expandWidget', true);
Collapse the chat window. Both methods are aliases.
JSSvyazio('minimizeWidget');
Svyazio('closeChat'); // alias
Completely hide the widget (button and window). Restore with show().
JSSvyazio('hide');
Show the widget after hide() or startHidden: true.
JSSvyazio('show');
Visitor Data
Fully overwrites visitor data. Fields: name, email, phone, notes, and any custom fields.
JSSvyazio('setIntegrationData', {
name: "John Smith",
email: "john@example.com",
phone: "+1 555 000-0000",
plan: "pro",
userId: "12345"
});
Partially updates data (merge). Pass null to delete a field.
JSSvyazio('updateIntegrationData', { email: "new@example.com" });
Svyazio('updateIntegrationData', { phone: null }); // delete
Position & Size
Move the chat button on screen. Available codes: bl, bc, br, lt, lm, lb, rt, rm, rb.
JSSvyazio('setButtonPosition', 'bl'); // bottom left
Svyazio('setButtonPosition', 'rt'); // top right
Change the round button diameter (px). Min 40, max 100.
JSSvyazio('setButtonSize', 72);
Set chat window width (px, min 280).
JSSvyazio('setChatWidth', 480);
Set chat window height (px, min 300).
JSSvyazio('setChatHeight', 700);
Override the widget's z-index. Useful if menus overlap the widget.
JSSvyazio('setZIndex', 100);
Colors
Override the widget color palette on the fly. Ideal for dynamic light/dark switching.
JSSvyazio('setColors', {
buttonBg: '#6C63FF',
buttonText: '#fff',
clientBubbleBg: '#e8e5ff',
agentBubbleBg: '#f4f4f5'
});
Reset colors to defaults from configuration.
JSSvyazio('resetColors');
Language
Switch the widget interface language. Available: 'ru', 'en', 'es', 'pt'.
JSSvyazio('setLanguage', 'en');
Svyazio('setLanguage', 'es');
Set language or override interface strings. Pass a string code or an object with string overrides.
JSSvyazio('setLocale', 'en');
Svyazio('setLocale', {
placeholder: 'Type your message…',
headerTitle: 'Support'
});
Actions
Display an automatic message from the bot in the chat window. Visible only to the visitor, not sent to agents until the visitor replies.
JSSvyazio('sendAutoMessage', 'Hi! Need help with your order?');
Track a page view manually. Useful for SPA apps where the URL changes without a full page reload.
JSSvyazio('pageView');
Route new conversations to a specific department. Pass null to reset to default.
JSSvyazio('setGroupId', 'sales_dept_id');
Svyazio('setGroupId', null); // reset
Lifecycle
Restart the widget while preserving configuration. Useful in SPA apps after route changes.
JSSvyazio('restart');
Completely destroy the widget: removes DOM elements and closes WebSocket. Cannot be restored without a page reload.
Use only if you need to completely remove the widget until the next page reload.
JSSvyazio('kill');
Callbacks
onNewMessage
JSwindow.SvyazioConfig = {
orgId: "YOUR_ORG_ID",
onNewMessage: function(msg) {
// msg.id, msg.text, msg.createdAt (ms), msg.type: "agent"|"client"|"bot"
console.log(msg);
}
};
// Example: unread counter in the page title
let unread = 0;
window.SvyazioConfig.onNewMessage = function(msg) {
if (msg.type === 'agent' || msg.type === 'bot') {
document.title = '(' + (++unread) + ') ' + document.title;
}
};
onAnalyticEvent
JSwindow.SvyazioConfig = {
orgId: "YOUR_ORG_ID",
onAnalyticEvent: function(eventName) {
// Google Analytics 4
gtag('event', eventName, { event_category: 'Live Chat' });
// Mixpanel / Amplitude
if (window.mixpanel) {
mixpanel.track('chat_' + eventName);
}
}
};
Usage Examples
Show chat after N seconds
JSsetTimeout(function() {
Svyazio('show');
Svyazio('openChat');
}, 15000);
Pass data after login
JSfunction onUserLogin(user) {
Svyazio('setIntegrationData', {
name: user.name,
email: user.email,
plan: user.plan,
clientId: 'user_' + user.id
});
}
Route VIP clients to priority department
JSif (currentUser.plan === 'enterprise') {
Svyazio('setGroupId', 'vip_dept_id');
}
Hide on specific pages
JSif (window.location.pathname === '/checkout') {
Svyazio('hide');
} else {
Svyazio('show');
}
Custom button
HTML<button id="my-chat-btn">Contact Support</button>
<script>
window.SvyazioConfig = {
orgId: "YOUR_ORG_ID",
customWidgetButton: "#my-chat-btn"
};
</script>
clientId — history across devices
JSwindow.SvyazioConfig = {
orgId: "YOUR_ORG_ID",
clientId: "user_" + currentUser.id
};
clientId must be permanent for the user. Do not use random or temporary values.
Migration from Chatra
Most Chatra JS API methods are supported in Svyazio. Migrating your code requires only renaming objects and calls:
- Replace
ChatraSetup→SvyazioSetup - Replace
ChatraIntegration→SvyazioIntegration - Replace all calls
Chatra('method')→Svyazio('method')
Core methods — openChat, hide, show, setIntegrationData, sendAutoMessage and others — are implemented and working. Some rare Chatra methods may be absent — check the reference table.
All Methods
| Method | Arguments | Description |
|---|---|---|
openChat | focus? | Open chat |
expandWidget | focus? | Open (desktop only) |
minimizeWidget | — | Collapse chat |
closeChat | — | Alias for minimizeWidget |
hide | — | Hide widget |
show | — | Show widget |
setIntegrationData | data | Set visitor data (overwrite) |
updateIntegrationData | data | Update visitor data (merge) |
setButtonPosition | code | Move button |
resetButtonPosition | — | Reset to config position |
setButtonSize | size | Button size (px) |
setChatWidth | width | Window width (px) |
setChatHeight | height | Window height (px) |
setZIndex | value | Widget z-index |
setColors | colors | Override colors |
resetColors | — | Reset colors |
setLanguage | code | Switch language |
setLocale | code | object | Language or string overrides |
sendAutoMessage | text | Auto message from bot |
pageView | — | Track page (SPA) |
setGroupId | id | null | Route to department |
restart | — | Restart widget |
kill | — | Destroy widget |