๐Ÿ›๏ธ Customer Website ยท Integration Example

A mock customer product landing page that integrates the AikeChat support widget with one <script> tag. A support icon appears in the lower-right corner; open it to chat with echo-bot.

Recommended No-code integration: data-* attributes

Use one <script> tag without writing any JS:

<script src="http://localhost:18080/sdk/leke-chat.umd.js" data-site-key="demo-site-key" async></script>

For more optional fields (username / phone / email / widget title / display language / skill group, etc.), see Initialization parameters below and use the matching data-* column.

Declarative config: window.AiKeChatConfig

Use this when you need to pass complex structures such as user.extra:

<script>
  window.AiKeChatConfig = {
    siteKey: 'demo-site-key',
    user: {
      externalUserId: 'biz-uid-12345',
      extra: { vipLevel: 'gold' }
    }
  };
</script>
<script src="http://localhost:18080/sdk/leke-chat.umd.js"></script>

Define the config before the SDK script. data-* and AiKeChatConfig can be used together; data-* overrides fields with the same name.

Programmatic API: AiKeChat.init()

Use this for dynamic configuration or on-demand mounting in an SPA:

<script src="http://localhost:18080/sdk/leke-chat.umd.js" data-auto-init="false"></script>
<script>
  AiKeChat.init({
    siteKey: 'demo-site-key',
    user: { externalUserId: 'biz-uid-12345', username: 'John Doe' },
    title: 'Customer Support'
  });
</script>

When the SDK starts, it calls /v1/visitor/auth to exchange the siteKey for a JWT, and all subsequent WebSocket connections include that JWT. user.deviceFp automatically falls back to localStorage, so returning visitors can be merged.

Verified message flow

  1. Page loads โ†’ SDK fetches /v1/visitor/auth {siteKey, user}
  2. biz-api validates the siteKey and domain allowlist โ†’ merges the customer โ†’ issues a JWT
  3. SDK connects to the im-gateway WebSocket with ?token=<JWT>
  4. im-gateway verifies the signature โ†’ extracts tenantId / customerId โ†’ registers them in the hub
  5. Send a message โ†’ NATS โ†’ persist-worker writes to the database โ†’ echo-agent replies โ†’ the widget displays it

Initialization parameters

The following fields support all three input methods: data-* attributes (recommended) / window.AiKeChatConfig / AiKeChat.init().

JS field data-* attribute Required Description
siteKeydata-site-keyYesCustomer SDK key
user.externalUserIddata-external-user-idNoUser ID in your system; recommended when merging users across devices
user.usernamedata-usernameNoUser name
user.phonedata-phoneNoPhone number
user.emaildata-emailNoEmail address
user.extraโ€”NoCustom key-value pairs; only supported by AiKeChatConfig / init()
titledata-titleNoWidget title
localedata-localeNozh-CN / zh-TW / en / id / ms
skillGroupIddata-skill-group-idNoSpecified skill group; leave empty to use the customer's default
Controldata-auto-init="false"NoDisables auto init; use this when calling AiKeChat.init() yourself

Bundle size

โ†˜ The lower-right corner shows the real support widget loaded from /sdk/leke-chat.umd.js