Skip to content

Control and events

Method
init(config) Mounts the widget. On a mounted widget, same as configure().
configure(patch) Changes any option.
open(), close(), toggle() Opens or closes the panel.
enable(), disable() Shows or hides the whole widget.
setToken(token) Signs a user in, e.g. after they log in to your site. null signs them out.
destroy() Unmounts the widget and resets its options. Event handlers stay subscribed.
on(event, handler) Subscribes to an event. Returns the function that unsubscribes.
Event Payload
open
close
message { role: "user" | "assistant", text, sessionId }, once per new message
error { message }: a failed request, stream or sign-in
document.querySelector("#help").addEventListener("click", () => SnipetWidget.open());
const off = SnipetWidget.on("message", (message) => {
analytics.track("chat_message", { role: message.role });
});