javascript api

Methods

Complete reference for all UserBoost JavaScript API methods

open()

Opens the chat panel. If the panel hasn't been loaded yet, it loads lazily on first open.

js
UserBoost.open();

close()

Closes the chat panel. The conversation state is preserved.

js
UserBoost.close();

toggle()

Toggles the chat panel open or closed.

js
UserBoost.toggle();

sendMessage(text)

Sends a message as if the visitor typed it. Opens the chat panel if it's closed.

js
UserBoost.sendMessage("What are your shipping rates?");
sendMessage(text)Method
ParameterTypeRequiredDescription
textstringRequiredThe message to send.

setVisibility(visible)

Shows or hides the entire widget (both the launcher bubble and the chat panel).

js
// Hide the widget
UserBoost.setVisibility(false);

// Show the widget
UserBoost.setVisibility(true);
setVisibility(visible)Method
ParameterTypeRequiredDescription
visiblebooleanRequiredtrue shows the widget, false hides it.

on(event, callback)

Registers an event listener for widget events.

js
UserBoost.on("open", () => {
  console.log("Chat opened");
});
on(event, callback)Method
ParameterTypeRequiredDescription
eventstringRequiredEvent name to listen for (open or close).
callbackfunctionRequiredHandler invoked when the event fires.

off(event, callback)

Removes a previously registered event listener.

js
const handler = () => console.log("opened");
UserBoost.on("open", handler);
UserBoost.off("open", handler);

destroy()

Removes the widget from the page entirely. Cleans up all event listeners and DOM elements.

js
UserBoost.destroy();

After calling destroy(), the widget cannot be re-initialized without reloading the page.