15-day Pro trial · no credit cardStart free →

API & webhooks

Embedded workspace & side panelsBeta

Embed the STINGIM agent workspace in your own admin panel and add custom side panels with signed context.

Embedding is in beta. Configure it under Settings → Embed & apps (requires the Integration permission).

Two features let you bring STINGIM into your own tools:

  • Embedded workspace — show the agent inbox inside your admin panel (or the Shopify admin) in an iframe, signed in as a specific agent, without a separate login.
  • Custom side panels — show your own pages (CRM, order system…) next to a conversation in the workspace, with a signed context so your page knows which customer and agent it is for.

Embedded workspace

Text
Your admin page             Your server                               STINGIM
 1. agent opens page ──────▶ 2. POST /v1/auth/embed/token (signed) ──▶ one-time token (60 s) + embed_path
 3. receives { token, embed_path } ◀──┘
 4. embed-sdk.js creates the iframe  chat.stingim.com<embed_path>#token=…  ──▶ token exchanged, embed session
 5. postMessage protocol v1 between your page and the iframe (strict origin checks)

1. Configure

  1. Generate API credentials: a Key ID (ek_…, not secret) and a Secret (es_…, shown once, server-side only). Rotating invalidates the old credentials and any unused tokens immediately.
  2. Allowed parent origins: https://host[:port] or a leftmost wildcard https://*.example.com (does not match the bare domain); up to 20. Used for the iframe's CSP frame-ancestors and for postMessage origin checks. For the Shopify admin use https://admin.shopify.com.
  3. Session length: 5–720 minutes (default 60). The session renews itself while open.
  4. Turn on Allow embedding.

2. Mint a token on your server

POST https://api.stingim.com/v1/auth/embed/token

HeaderValue
X-Embed-KeyKey ID
X-Embed-TimestampUnix seconds, within 5 minutes of server time
X-Embed-Signaturev1= + hex(HMAC_SHA256(secret, "<timestamp>.<raw body>"))

Body (max 8 KiB) — identify the agent by exactly one of member_email or member_id; the agent must be an active member of the project:

JSON
{ "member_email": "[email protected]", "conversation_id": "optional: conversation to open" }

Response 200:

JSON
{ "token": "et_…", "expires_in": 60, "project_id": "…", "embed_path": "/embed/inbox?project_id=…" }

Errors use real HTTP status codes and { "code", "message" }: 401 missing_signature / invalid_key / invalid_signature / stale_timestamp, 403 embed_disabled, 404 member_not_found, 409 replayed (each signature works once), 400 invalid_body, 429 rate_limited (120 per minute per key).

JavaScript
import crypto from 'node:crypto';

export async function mintEmbedToken(memberEmail) {
  const body = JSON.stringify({ member_email: memberEmail });
  const ts = Math.floor(Date.now() / 1000);
  const sig = crypto.createHmac('sha256', process.env.STINGIM_EMBED_SECRET).update(`${ts}.${body}`).digest('hex');
  const res = await fetch('https://api.stingim.com/v1/auth/embed/token', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-Embed-Key': process.env.STINGIM_EMBED_KEY_ID,
      'X-Embed-Timestamp': String(ts),
      'X-Embed-Signature': `v1=${sig}`,
    },
    body,
  });
  if (!res.ok) throw new Error(`embed token: ${res.status} ${await res.text()}`);
  return res.json(); // { token, embed_path, ... }
}

Tokens are single-use and valid for 60 seconds: mint one per page view and never cache it. Only send token and embed_path to the browser — never the secret.

3. Mount the iframe

HTML
<div id="workspace" style="height: 720px"></div>
<script src="https://chat.stingim.com/embed-sdk.js"></script>
<script>
  const ws = WorkspaceEmbed.mount({
    container: '#workspace',
    host: 'https://chat.stingim.com',
    embedPath: data.embed_path, // from your server
    token: data.token,          // from your server
    onEvent(type, payload) {
      if (type === 'unreadCount') updateBadge(payload.count);
      if (type === 'sessionExpired') location.reload(); // mint a new token
    },
  });
  // ws.openConversation('<conversation_id>');
  // ws.setStatus('away');   // online | away | busy | offline
  // ws.logout();
  // ws.destroy();
</script>

postMessage protocol v1

Envelope: { ns: 'ws-embed', v: 1, type, payload? }. Messages with another version or shape are ignored.

Parent → iframePayload
hello— (sent by the SDK on iframe load)
openConversation{ conversationId }
setStatus{ status: 'online' | 'away' | 'busy' | 'offline' }
logout—
Iframe → parentPayload
ready{ version: 1 }
unreadCount{ count }
newConversation{ conversationId }
conversationAssigned{ conversationId }
agentStatus{ status: 'online' | 'busy' | 'offline' }
resize{ height }
sessionExpired / loggedOut—

The embedded session can only use the inbox: settings, members, channels and billing are not available, even for administrators. The session lives in the tab's memory / sessionStorage and never sets console cookies.

Custom side panels

Under Settings → Embed & apps → Custom side panels, add a panel: name, URL template, height (120–2000 px), visible roles, order, and whether it may insert text into the reply box. Up to 20 per project. Creating or rotating a panel returns a one-time signing secret (ps_…). Panels appear in the customer sidebar's Apps tab.

URL template

  • Must be https://; the host cannot contain placeholders; panel_ctx and panel_sig are reserved parameter names.
  • Placeholders: {contact_id} {external_user_id} {email} {phone} {conversation_id} {channel} {lang} — filled from server data and URL-encoded, so they cannot inject parameters or paths.
  • {external_user_id} is only set for contacts verified through identity verification.

Example: https://crm.example.com/customers?email={email}&uid={external_user_id}

Verify the signed context

STINGIM appends panel_ctx = base64url(JSON { v: 1, panel_id, project_id, conversation_id, contact_id, external_user_id, member_id, iat, exp, nonce }, with exp = iat + 300) and panel_sig = hex(HMAC_SHA256(panel_secret, panel_ctx)). Verify on your server and trust only the signed fields:

JavaScript
import crypto from 'node:crypto';

export function verifyPanelContext(query, secret) {
  const ctx = String(query.panel_ctx || '');
  const sig = String(query.panel_sig || '');
  const expected = crypto.createHmac('sha256', secret).update(ctx).digest('hex');
  if (sig.length !== expected.length || !crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected))) return null;
  const data = JSON.parse(Buffer.from(ctx, 'base64url').toString('utf8'));
  if (data.v !== 1 || Math.floor(Date.now() / 1000) > data.exp) return null;
  return data; // placeholder values in the URL are a convenience only and are not signed
}

Panels render in a sandboxed iframe (allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox, referrerpolicy="no-referrer", no top-level navigation).

Insert text into the reply box

If the panel is allowed to insert text:

JavaScript
window.parent.postMessage({ ns: 'ws-panel', v: 1, type: 'insertText', text: 'Your order #1001 has shipped.' }, '*');

Text (up to 5,000 characters) is appended to the reply box; it is never sent automatically.

Found a mistake? Email [email protected]