API Reference
Complete reference for everything the SDK exposes.
createWidget(options)
Initializes the widget. Returns an instance with control methods.
import { createWidget } from "@bitpalm/ai-agents";
const widget = createWidget({
slug: string,
token?: string,
locale?: string,
theme?: "auto" | "light" | "dark",
baseUrl?: string,
zIndex?: number,
autoIdentify?: boolean,
quickLinks?: QuickLink[],
});See Configuration for option details.
Methods
Visibility
widget.open(): void
widget.close(): void
widget.toggle(): void
widget.isOpen(): booleanSend a message
widget.send(message: string): voidOpens the widget if closed, then submits the message as if the user typed it. See Programmatic Messages.
Identify
widget.identify(payload: {
externalUserId?: string;
name?: string;
email?: string;
phone?: string;
company?: string;
// Optional signed payload for verified data:
signature?: string;
signedAt?: number;
signatureVersion?: "v1";
}): voidMerges with previous identify calls. See Identify.
Custom Context
widget.context(data: Record<string, unknown>): void
widget.resetContext(): voidMerges by default. Total payload limited to 4 KB. See Context.
Quick links
widget.setQuickLinks(links: QuickLink[] | null): void
type Text = string | Record<string, string>; // "Prices" or { en: "Prices", de: "Preise" }
interface QuickLink {
label: Text; // button text, at most 40 characters
question?: Text; // what the button sends to the agent
url?: string; // or a page it opens: https://, mailto: or tel:
pages?: string; // "*" (default), "/pricing" or "/shop/*", several separated by commas
}Sets the buttons under the greeting for this embed, at most 8. They replace the quick links from the dashboard and show at once, for example after login or a page change. Every link whose pages match shows, in your order. An empty list shows none, null goes back to the ones from the dashboard.
widget.setQuickLinks([
{ label: { en: "My rent", de: "Meine Miete" }, question: { en: "When is my rent due?", de: "Wann ist meine Miete fällig?" } },
{ label: "Open a ticket", question: "I want to report a problem.", pages: "/portal/*" },
]);For quick links per role from the dashboard, see Identify.
Theme
widget.setTheme(theme: "auto" | "light" | "dark"): voidSwitches the widget colors. "auto" follows the website again. See Light & Dark Theme.
Proactive messages
widget.disableTriggers(): void
widget.enableTriggers(): voidSwitches proactive messages off and back on at runtime, for example while a checkout is open. enableTriggers() goes back to what the triggers option says. See Own Chat Button.
Events
widget.on(event: EventName, handler: (data: any) => void): () => voidReturns an unsubscribe function. See Events for the list.
Tear down
widget.destroy(): voidRemoves the widget DOM and unbinds all listeners.
<BitPalmAgent /> (React)
import { BitPalmAgent } from "@bitpalm/ai-agents/react";
<BitPalmAgent
slug="..."
token="..."
locale="en"
theme="auto"
zIndex={9999}
autoIdentify={true}
quickLinks={[{ label: "Prices", question: "What does it cost?" }]}
/>A new quickLinks array shows at once, the rest of the props only count on the first render.
The component renders nothing visible itself, it manages the widget lifecycle. Place it once in your root layout.
Pass onReady={(widget) => …} to get the widget instance, for open(), on() and the rest of the methods above. That is what you need with launcher={false} and a button of your own.
To call identify, context, send, etc., dispatch browser events (see below).
Attributes
Every element the widget adds to your page carries a fixed attribute: data-bitpalm-launcher on the round button, data-bitpalm-trigger on the bubble of a proactive message and data-bitpalm-chat on the chat iframe.
Browser events
For setups where you don't have a widget instance reference (script tag, React component), you can control the widget via window.dispatchEvent:
bitpalm-identify
window.dispatchEvent(
new CustomEvent("bitpalm-identify", {
detail: {
slug: "your-agent-slug",
externalUserId: "user_42",
email: "[email protected]",
},
})
);bitpalm-context
window.dispatchEvent(
new CustomEvent("bitpalm-context", {
detail: {
slug: "your-agent-slug",
cart: { total: 99 },
},
})
);bitpalm-quick-links
window.dispatchEvent(
new CustomEvent("bitpalm-quick-links", {
detail: {
slug: "your-agent-slug",
links: [{ label: "Prices", question: "What does it cost?" }], // null: back to the dashboard
},
})
);bitpalm-send
window.dispatchEvent(
new CustomEvent("bitpalm-send", {
detail: {
slug: "your-agent-slug",
message: "What can you tell me about plan X?",
},
})
);bitpalm-theme
window.dispatchEvent(
new CustomEvent("bitpalm-theme", {
detail: {
slug: "your-agent-slug",
theme: "dark", // "light", "dark" or "auto"
},
})
);bitpalm-open / bitpalm-close
window.dispatchEvent(new CustomEvent("bitpalm-open", { detail: { slug: "your-slug" }}));
window.dispatchEvent(new CustomEvent("bitpalm-close", { detail: { slug: "your-slug" }}));The slug in the detail is required so multi-agent setups (rare) target the right widget.
TypeScript types
import type {
WidgetOptions,
WidgetInstance,
IdentifyPayload,
EventName,
} from "@bitpalm/ai-agents";Bundle size
| Build | Gzipped |
|---|---|
@bitpalm/ai-agents (vanilla) | ~6 KB |
@bitpalm/ai-agents/react | ~7 KB |
| Script tag (UMD via unpkg) | ~7 KB |
The widget UI itself (chat window, message rendering) loads from the BitPalm domain in a sandboxed iframe — it doesn't ship in your bundle.
Privacy & opt-out
Visitors with localStorage["_bp_optout"] = "1" are excluded from tracking. The widget still works as a chat surface but treats them as anonymous (no visitor ID, no beacons).