For Developers

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>
Command Queue

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

ParameterTypeDefaultDescription
buttonStyle'round' | 'tab''round'Chat button style.
buttonPositionstring'br'Button position: bl, bc, br, lt, lm, lb, rt, rm, rb.
buttonSizenumber60Round button size (px).
chatWidthnumber400Chat window width (min. 280px).
chatHeightnumber600Chat window height (min. 300px).
zIndexnumber999999Widget z-index.
accentColorstringfrom settingsAccent color, e.g. '#6C63FF'.
colorsobjectColor scheme (see setColors).

Behavior

ParameterTypeDefaultDescription
startHiddenbooleanfalseHide widget on load. Show it with Svyazio('show').
disabledOnMobilebooleanfalseDo not show on mobile devices.
mobileOnlybooleanfalseShow only on mobile devices.
disableChatOpenHashbooleanfalseDisable URL hash #svyazioChatExpanded control.
deferredLoadingbooleanfalseLoad widget after full page load.
customWidgetButtonstringCSS selector for custom button. Default button is hidden.

Widget Text

ParameterTypeDescription
headerTextstringChat window header title.
welcomeTextstringWelcome text on first open.
onlineTitlestringSubtitle when agents are online.
offlineTitlestringSubtitle when agents are offline.
offlineTextstringText when no one is online.

Language & Locale

ParameterTypeDescription
localestring | objectLanguage code ('ru', 'en', 'es', 'pt') or an object with interface string overrides.
languagestringAlias for locale.

Visitor Data

ParameterTypeDescription
clientIdstringUnique user ID from your system — merges history across devices and sessions.
groupIdstringDepartment ID for routing conversations (Settings → Departments).

Callbacks

ParameterTypeDescription
onNewMessagefunction(msg)On each new message. msg: { id, text, createdAt, type }
onAnalyticEventfunction(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>
On Mobile

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

Svyazio('openChat', focus?)

Open the chat window. true — focus the input field.

JSSvyazio('openChat');
Svyazio('openChat', true); // with focus
Svyazio('expandWidget', focus?)

Similar to openChat, but ignores mobile calls. Useful for desktop triggers.

JSSvyazio('expandWidget', true);
Svyazio('minimizeWidget')  /  Svyazio('closeChat')

Collapse the chat window. Both methods are aliases.

JSSvyazio('minimizeWidget');
Svyazio('closeChat'); // alias
Svyazio('hide')

Completely hide the widget (button and window). Restore with show().

JSSvyazio('hide');
Svyazio('show')

Show the widget after hide() or startHidden: true.

JSSvyazio('show');

Visitor Data

Svyazio('setIntegrationData', 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"
});
Svyazio('updateIntegrationData', data)

Partially updates data (merge). Pass null to delete a field.

JSSvyazio('updateIntegrationData', { email: "new@example.com" });
Svyazio('updateIntegrationData', { phone: null }); // delete

Position & Size

Svyazio('setButtonPosition', code)

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
Svyazio('setButtonSize', size)

Change the round button diameter (px). Min 40, max 100.

JSSvyazio('setButtonSize', 72);
Svyazio('setChatWidth', width)

Set chat window width (px, min 280).

JSSvyazio('setChatWidth', 480);
Svyazio('setChatHeight', height)

Set chat window height (px, min 300).

JSSvyazio('setChatHeight', 700);
Svyazio('setZIndex', value)

Override the widget's z-index. Useful if menus overlap the widget.

JSSvyazio('setZIndex', 100);

Colors

Svyazio('setColors', 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'
});
Svyazio('resetColors')

Reset colors to defaults from configuration.

JSSvyazio('resetColors');

Language

Svyazio('setLanguage', code)

Switch the widget interface language. Available: 'ru', 'en', 'es', 'pt'.

JSSvyazio('setLanguage', 'en');
Svyazio('setLanguage', 'es');
Svyazio('setLocale', code | object)

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

Svyazio('sendAutoMessage', text)

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?');
Svyazio('pageView')

Track a page view manually. Useful for SPA apps where the URL changes without a full page reload.

JSSvyazio('pageView');
Svyazio('setGroupId', id | null)

Route new conversations to a specific department. Pass null to reset to default.

JSSvyazio('setGroupId', 'sales_dept_id');
Svyazio('setGroupId', null); // reset

Lifecycle

Svyazio('restart')

Restart the widget while preserving configuration. Useful in SPA apps after route changes.

JSSvyazio('restart');
Svyazio('kill')

Completely destroy the widget: removes DOM elements and closes WebSocket. Cannot be restored without a page reload.

Irreversible Operation

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
};
Important

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:

  1. Replace ChatraSetupSvyazioSetup
  2. Replace ChatraIntegrationSvyazioIntegration
  3. Replace all calls Chatra('method')Svyazio('method')
Migration takes just a few minutes

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

MethodArgumentsDescription
openChatfocus?Open chat
expandWidgetfocus?Open (desktop only)
minimizeWidgetCollapse chat
closeChatAlias for minimizeWidget
hideHide widget
showShow widget
setIntegrationDatadataSet visitor data (overwrite)
updateIntegrationDatadataUpdate visitor data (merge)
setButtonPositioncodeMove button
resetButtonPositionReset to config position
setButtonSizesizeButton size (px)
setChatWidthwidthWindow width (px)
setChatHeightheightWindow height (px)
setZIndexvalueWidget z-index
setColorscolorsOverride colors
resetColorsReset colors
setLanguagecodeSwitch language
setLocalecode | objectLanguage or string overrides
sendAutoMessagetextAuto message from bot
pageViewTrack page (SPA)
setGroupIdid | nullRoute to department
restartRestart widget
killDestroy widget