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.

UserBoost.open();

close()

Closes the chat panel. The conversation state is preserved.

UserBoost.close();

toggle()

Toggles the chat panel open or closed.

UserBoost.toggle();

sendMessage(text)

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

UserBoost.sendMessage("What are your shipping rates?");

Parameters:

  • text (string, required) — the message to send

setVisibility(visible)

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

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

// Show the widget
UserBoost.setVisibility(true);

Parameters:

  • visible (boolean, required) — true to show, false to hide

on(event, callback)

Registers an event listener for widget events.

UserBoost.on("open", () => {
  console.log("Chat opened");
});

Parameters:

  • event (string, required) — event name ("open", "close")
  • callback (function, required) — handler function

off(event, callback)

Removes a previously registered event listener.

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.

UserBoost.destroy();
⚠️

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