@developer.notchatbot/webchat
Version:
A beautiful React chatbot widget with single-file bundle
41 lines (40 loc) • 2.06 kB
TypeScript
/**
* Self-initialization from the bundle's own <script> URL.
*
* Used by the Tiendanube 1-click install (Scripts API): Tiendanube injects
* <script src="https://unpkg.com/...bundle.min.umd.cjs?apiKey=<uid>&s=<base64url>">
* and the bundle configures itself from those params — zero requests to the
* NotChatbot backend on page view. The `s` payload is built SERVER-SIDE when
* the script is (re)associated to the store, so this module only decodes it;
* it never derives styles on its own.
*
* ⚠️ CRITICAL BACKWARD COMPATIBILITY ⚠️
* Every existing GTM/manual customer loads this same bundle from @latest
* WITHOUT query params. For any src without `apiKey` this module MUST return
* null and MUST NOT throw — the bundle then behaves exactly as before
* (waiting for a manual WebChat.initialize). Keep every code path here
* defensive: a broken payload degrades to apiKey-only defaults, never to an
* error that could interfere with the bundle load.
*/
/** Versioned payload carried in the `s` query param (base64url of its JSON). */
export interface StylesParamV1 {
v: 1;
/** Fully-resolved WebChatConfig (minus apiKey), built server-side. */
c: Record<string, unknown>;
/** CSS for window.injectWebChatCSS (button resize), or null. */
css: string | null;
}
export interface SelfInitPayload {
apiKey: string;
/** Resolved config from `s`, or null to initialize with defaults. */
config: Record<string, unknown> | null;
injectCss: string | null;
}
/** Encodes a styles payload to base64url. Exported for tests and tooling; production encoding lives server-side. */
export declare function encodeStylesParam(payload: StylesParamV1 | Record<string, unknown>): string;
/**
* Parses the bundle's own script src. Returns null unless the URL carries an
* `apiKey` query param (the self-init opt-in marker). A present-but-broken
* `s` param degrades to apiKey-only (default appearance) instead of failing.
*/
export declare function parseSelfInitFromSrc(src: string): SelfInitPayload | null;