Customer Service
CS Widget
Integrate customer service with visitor links, a site script, or the npm package.
Visitor links and parameters · Script / npm integration
Visitor link integration
Open the CS console, select a domain, and copy the base visitor URL from Sites & keys → Link entry. It opens a fullscreen chat without embedding a script on your website. Use the console URL; the domains below are examples.
https://cs.example.com/?k=sk_xxx&u=10001&nick=%E5%BC%A0%E4%B8%89
This passes user ID 10001 and display name “张三”. Keep k in ordinary links; append parameters with & after an existing query. Use URL to encode names, spaces, plus signs, and special characters:
const url = new URL('https://cs.example.com/?k=sk_xxx');
url.searchParams.set('u', String(currentUser.id));
url.searchParams.set('nick', currentUser.name);
url.searchParams.set('extra', JSON.stringify({
memberLevel: 'VIP',
source: 'mall'
}));
window.location.href = url.toString();
Replace the example URL with the console base link. When signatures are required, use a complete link generated by your backend. Changing its user ID or nickname requires a new signature.
All URL parameters
There are 37 parameters, counting aliases once and t / s separately. Ordinary links require a site key; secure links use a token instead. Other fields are optional. Choose one alias per field; a nonempty long name takes precedence.
| Parameter (alias) | Description |
|---|---|
k / appKey | Site key from the console; required for ordinary links. |
u / externalUserId | Stable user ID from your business system, not the internal visitor ID. |
nick / nickname | User display name. |
avatar | Avatar URL. |
email | Email address. |
phone | Phone number. |
extra | JSON object with visitor context such as membership tier or source; see limits below. |
order | Order product card JSON; sent once after the standalone page establishes or restores a conversation. |
t | Signature timestamp in seconds; required with s when signatures are enforced. |
s | HMAC-SHA256 signature as a hexadecimal string. |
entryToken / #e= | Single-use secure entry token. Choose one form; do not mix with ordinary entry data. |
locale | UI locale, e.g. zh-CN, zh-TW, en-US; otherwise resolved from saved, site, or browser preferences. |
theme | light / dark / auto |
hideHeader / hideHead | Hide the standalone header for iframe embedding, e.g. hideHeader=1. |
apiBase | Gateway origin without /api/v1; inferred from the Widget script URL by default. |
wsBase | WebSocket address; inferred from apiBase by default. |
| Appearance and behavior | Description |
|---|---|
primaryColor | Brand color, e.g. #409EFF; encode the hash with URLSearchParams. |
primaryColorAccent | Gradient accent color, used with primaryColor. |
backgroundImage | Chat panel background image URL. |
headerTitle | Header title. |
headerSubtitle | Header subtitle. |
headerBackground | Header background: CSS color, gradient, or url(...). |
mode | embed / standalonethe visitor page already enforces standalone. |
entry | linkset automatically on the standalone page. |
defaultOpen | Whether to open by default; standalone always opens, even when false is passed. |
zIndex | Numeric widget stacking order. |
mock | Local simulation without a real agent connection; debugging only, incompatible with secure tokens. |
| Embedded mode parameters | Description |
|---|---|
position | br bottom right, bl bottom left, tr top right, tl top left. |
offsetX | Horizontal margin, 0–200 px. |
offsetY | Vertical margin, 0–200 px. |
panelWidth | Desktop panel width, 280–720 px. |
panelHeight | Desktop panel height, 360–900 px. |
panelRadius | Panel corner radius, 0–32 px. |
buttonSize | Floating launcher size, 40–96 px. |
buttonShape | circle / pill |
buttonLabel | Pill launcher label. |
buttonIcon | Launcher image URL or SVG string. |
These 10 shared-parser options apply to embedded mode. Standalone has no launcher and forces a fullscreen panel with no margins or corner radius, so these options do not change its layout. For embedded scripts, use the widget.js query string.
true / 1 / yes → true; false / 0 / no → false. Unknown top-level parameters do not become visitor data; put custom fields in extra.
Custom context and orders
extra must be a plain JSON object: maximum 32 KB, depth 5, 100 nodes including the root, and 30 items per array. Keys are limited to 64 characters and cannot contain dots or control characters, start with $, or equal __proto__, prototype, or constructor. String values are truncated to 2000 characters. Do not include secrets or login tokens.
Use url.searchParams.set('extra', JSON.stringify(data)) without encodeURIComponent to avoid double encoding. Only use encodeURIComponent(JSON.stringify(data)) when assembling a URL manually. The 32 KB data limit does not guarantee that a browser or proxy accepts a URL that long; use secure entry for larger context.
Orders are separate messages, not extra fields. order requires title, orderNo, and an HTTPS url. Optional fields: imageUrl (HTTPS), description, price (nonnegative), quantity (positive integer), currency, currencySymbol, orderTime. Invalid cards are ignored:
url.searchParams.set('order', JSON.stringify({
title: 'Backpack',
orderNo: 'ORDER-10001',
url: 'https://shop.example.com/orders/10001',
price: 89.9,
quantity: 1
}));
See business data and the business data playground.
Identity settings and signatures
Enable “Allow identity fields in the query” under the site Link entry settings. Disabling it ignores u, nick, email, and phone on ordinary links; it does not discard profile data carried by a secure token.
When HMAC signatures are required, ordinary links must include t / s. Generate a signed link in the console by entering the external user ID and nickname, or calculate it on your backend with the site signing secret:
HMAC-SHA256(signSecret, [appKey, String(t), externalUserId || '', nickname || ''].join(String.fromCharCode(10))) → hex
Join the raw values with newlines before URL encoding; t is a Unix timestamp in seconds. Site signature TTL is 60–3600 seconds, default 300. Keep the secret server-side. Changing k, u, nick, or t requires signing again; missing, expired, or invalid signatures are rejected.
The signature covers only appKey, t, externalUserId, and nickname, not avatar, email, phone, extra, or order; it does not encrypt those fields. Signed links can be revisited within their TTL. Use entryToken for single-use access.
Single-use secure entry
Your backend calls POST /api/v1/cs/entry-token with appKey + appSecret and externalUserId, nickname, avatar, email, phone, extra. The response includes entryToken, expiresAt, and expiresIn. Never expose appSecret in a browser or link; browser calls to this endpoint are rejected. Use the returned expiry; a consumed token cannot be reused.
https://cs.example.com/?locale=zh-CN#e=cset_...
https://cs.example.com/?locale=zh-CN&entryToken=cset_...
Prefer #e=; use entryToken= only when the channel cannot preserve fragments. Do not duplicate either form or supply both. Secure entry cannot include k / appKey, u / externalUserId, nick / nickname, avatar, email, phone, extra, t / s, or order. Display options such as locale, theme, and hideHeader remain available. Token issuance does not support order; send orders separately after entering the conversation.
Script / npm integration
pnpm add @starim-io/cs-widget
import StarIMCS, { ApiError } from '@starim-io/cs-widget'
await StarIMCS.init({ appKey: 'sk_xxx', apiBase: 'https://<your-api-host>' })
StarIMCS.on('conversation:end', (event) => console.log(event))
StarIMCS.on('conversation:new', (event) => console.log(event))
try {
const result = await StarIMCS.endConversation()
console.log(result.conversation.customerService.stateVersion)
StarIMCS.startNewConversation()
} catch (error) {
if (error instanceof ApiError) console.error(error.code)
}
Panel vs. conversation
close()only collapses the panel. It never ends the support conversation.endConversation()ends the current business conversation and resolves withVisitorEndConversationResult. Pending sends/uploads block the operation until they finish.- After a successful end, call
startNewConversation(). The next successfully sent message creates and binds a new conversation.
Lifecycle events
conversation:end {
conversationId, closeReason?,
closedBy: 'visitor' | 'agent' | 'system',
satisfactionStatus, remote, alreadyEnded
}
conversation:new { conversationId, previousConversationId }
conversation:end fires at most once per conversation generation. remote=true means the close arrived from the service side. conversation:new fires only after the first message succeeds and the new ID is bound.
Precondition and errors
Call visitor end after the handshake returns capabilities.visitorEndConversation === true. Common codes include CS_CAPABILITY_UNAVAILABLE, CS_CONVERSATION_UNAVAILABLE, CS_CONVERSATION_ID_MISMATCH, CS_CONVERSATION_NOT_FOUND, CS_CONVERSATION_ENDED, CS_CONVERSATION_STILL_OPEN, CS_CONVERSATION_BUSY_LOCAL, CS_CONVERSATION_STATE_CHANGED, CS_CONVERSATION_BUSY, and CS_FEATURE_DISABLED.
Use the gateway origin from the CS console snippet as apiBase, without /api/v1.
