Web JS SDK
Methods
Reference for window.stingIm: show, hide, open, close, identify, logout, setTags, setContext, setStyle, getStatus, onReady and destroy.
All methods live on window.stingIm. Calls made before the widget's handshake completes are queued and delivered in order, so you can call them right after the install code runs.
Overview
| Method | Description |
|---|---|
show() | Show the widget and open the chat panel (undoes hide()). |
hide() | Hide the widget completely (launcher and panel). No proactive invitations pop up while hidden. Stays hidden until show() or open(). |
open() | Open the chat panel. Also undoes hide(). |
close() | Collapse the chat panel and keep the launcher. |
identify(user) | Declare or switch the logged-in user. Returns Promise<boolean>. |
logout() | The user logged out: clear the visitor session in this browser. Returns Promise<boolean>. |
setTags(tags) | Replace the entry tags set from JavaScript. |
setContext({ product?, orderNo? }) | Business context passed to the agent. Replaces the previous context. |
setStyle(css) | Adjust position and stacking. |
getStatus() | Current state of the widget. |
onReady(cb) | Run cb(stingIm) when the widget is ready. Returns an unsubscribe function. |
destroy() | Remove the widget from the page. |
version | Host protocol version (currently 2). |
show, hide, open, close
stingIm.open(); // open the panel
stingIm.close(); // collapse to the launcher
stingIm.hide(); // remove launcher + panel from view
stingIm.show(); // bring it back and open the panelhide() is a real hidden state: the widget cannot make itself visible again (for example to show a proactive invitation) until you call show() or open().
identify(user)
Declares the logged-in user or switches to a different one.
const ok = await stingIm.identify({
userId: 'u_123', // required, 1–255 characters, no control characters
userHash: '9f86d0…', // optional: 64 hex characters, computed on your server
exp: 1767225600, // optional: Unix seconds, only together with userHash
name: 'Jane Doe', // optional, display only, up to 64 characters
email: '[email protected]' // optional, display only, up to 254 characters
});- Resolves
trueonce the claim has been delivered to the widget, andfalseif the input is invalid (aconsole.warnexplains why) or the widget was destroyed. truedoes not mean the identity was verified. The backend's verdict arrives as thestingim:identityevent and ingetStatus().identityStatus.- A
userHashthat is present but not 64 hex characters rejects the whole claim (it is not downgraded to an unsigned claim).expwithoutuserHashis invalid too.
See Identity verification for how to compute userHash.
logout()
await stingIm.logout();Clears the visitor session stored in this browser so the next person starts as a fresh anonymous visitor. Call it when the user signs out of your site — especially on shared devices.
setTags(tags)
stingIm.setTags(['vip', 'kol_anna']);Replaces the entry tags previously set from JavaScript (stingImSettings.tags or an earlier setTags). Up to 20 tags, each 1–64 characters; invalid entries are dropped. Tags drive routing rules configured in the console.
setContext(context)
stingIm.setContext({ product: 'Trail Runner 2 — size 42', orderNo: 'SO-10086' });Business context for the conversation, for example when the visitor continues the chat on their phone. product is up to 200 characters, orderNo up to 64. Each call replaces the whole context; non-string fields are ignored.
setStyle(css)
stingIm.setStyle({ bottom: '90px', right: '24px', zIndex: '1000' });Fine-tunes the widget's position and stacking. Only right, bottom, left, top, zIndex, maxWidth and maxHeight are accepted, as plain string values (letters, digits, spaces, . , % + -, at most 64 characters). Anything else is ignored with a console warning. Use show() / hide() for visibility. On phones the open panel is full-screen and your overrides apply again when it collapses.
getStatus()
stingIm.getStatus();
// { ready, visible, open, hidden, identityStatus, error, destroyed }| Field | Meaning |
|---|---|
ready | The widget has finished initialising (visitor identity established) and can chat. |
visible | The widget is currently visible on the page. |
open | The chat panel is open. |
hidden | Hidden by hide(). |
identityStatus | Verdict of the latest identity claim: anonymous, verified, unverified or rejected; null if unknown. |
error | Reason for a fatal error (for example a rejected configuration); null normally. |
destroyed | destroy() has been called. |
onReady(cb)
const off = stingIm.onReady(function (api) {
api.setTags(['returning']);
});
// off(); // cancel if it has not fired yetCalls cb once the widget is ready. If it is already ready, cb runs asynchronously right away. You can also pass onReady in stingImSettings.
destroy()
stingIm.destroy();Removes the iframe, event listeners and URL polling timer, restores the page title and deletes window.stingIm. Pending queued calls resolve with false. Afterwards you can insert the install code again. Removing only the <script> tag does not remove the widget — see Single-page apps.
Found a mistake? Email [email protected]
