我们如何帮助您?

ChatKit JavaScript API

Configure and control ChatKit programmatically using Javascript.
最后由 Knoon ai 于 2025年11月9日 1:59 更新

The loader exposes a small runtime API:

Methods

  • init(config) → void
    Programmatically initializes the widget (use once per page). Only needed when you don’t use the auto‑init script tag.

  • open() / close() → void
    Opens or closes the chatbox.

  • active() / inactive() → void
    Shows or hides the floating launcher button. (Useful if you want a custom opener.)

  • destroy() → void
    Completely removes the widget from the page so you can re‑initialize later.

Optional Hooks

Provide any of the following properties before initialization:

  • async signIn() → { jwt, expiresAt, domain? } | null
    Return short‑lived credentials for the current visitor. If you return null/undefined, the widget proceeds as a guest or, when manualSignIn is enabled, shows a “Sign in” button to the user.

  • async requestSignIn() → { jwt, expiresAt, domain? } | null
    Called when the user clicks “Sign in” inside the widget. Implement your own modal/login and resolve with credentials.

  • on(event, payload) → void
    Receive lifecycle callbacks:

    • on('loaded', 'widget') — the launcher is ready.

    • on('loaded', 'chatbox') — the chatbox finished loading.

    • on('closed') — the chatbox has been closed.

Credential shapejwt is a string; expiresAt can be a UNIX timestamp (ms/s) or ISO datetime; domain is optional if you need cross‑subdomain session scoping.

找不到您想要的内容?立即与我们聊天。