Skip to main content
The Chatbase embed script exposes the window.chatbase object with methods to control your chat bubble programmatically.

Methods

open(options?)

Opens the chat bubble. Optionally sends a message when it opens.
Parameters
string
A message to send automatically when the chat bubble opens.
boolean
default:"false"
When true, the sent message is hidden and the chat bubble stays closed until the bot starts replying — so it looks like the assistant reached out proactively. Only applies when message is set.

close()

Closes the chat bubble.

resetChat()

Clears the current conversation and starts a new session.
Your chat bubble configuration and custom initial messages are preserved after reset.

Runtime Options

Override a bounded set of your agent’s configured options for the current page load — the chat bubble’s display name, footer, message placeholder, dismissible notice, initial messages, and suggested messages. Overrides are never persisted: reloading the page or calling resetOptions returns the chat bubble to its dashboard configuration.

setOptions(options)

All keys are optional — pass only the ones you want to override. Parameters
string
Overrides the chat bubble header title. Also updates the launcher button’s accessibility labels so assistive technology announces the same name. Maximum 100 characters.
Overrides the footer text. Maximum 1000 characters.
string
Overrides the message input placeholder. Maximum 100 characters.
string
Overrides the dismissible notice shown above the message input. Maximum 500 characters.
string[]
Overrides the agent’s initial messages. Array of non-empty strings, limited to 1000 characters in total. Applies immediately if the conversation hasn’t started; otherwise it takes effect on the next fresh conversation (for example after resetChat()). Writes the same setting as setInitialMessages — the last call wins, whichever method made it.
string[]
Replaces the dashboard-configured suggested message chips. Up to 4 entries, each a non-empty string of at most 200 characters. Suggestions the AI generates during the conversation still take precedence over this override.
Invalid keys or values are skipped with a console.error; valid keys in the same call still apply. setOptions never truncates — an oversize value is rejected. (The legacy setInitialMessages method instead truncates to 1000 characters, preserving its documented behavior.)

resetOptions(fields?)

Clears runtime overrides, returning those options to the agent’s dashboard configuration.
Parameters
object
An object mapping option keys to true for each override to clear. When omitted, every runtime override is cleared.

Per-field methods

Each option also has a dedicated setter that behaves exactly like setOptions with that single key:

Examples

Combine these methods with event listeners to build powerful, context-aware chat experiences.

Custom Buttons

Trigger chat bubble actions from your own UI elements:

Answer FAQ Questions

Turn static FAQ entries into live answers — open the chat bubble with the question pre-filled:
Chat Bubble Open Proactive

Proactive Message on Intent

Reach out automatically when a visitor lingers on a high-intent page. The message is hidden until the bot replies, so it feels like the assistant started the conversation.

Time-Based Reset

The 24-hour example uses localStorage to persist the last message time across page reloads.

Reset After Tool Completion

Reset on Keywords

Always add a delay before resetting so users can read the final AI response.

Reset on Navigation

Start fresh conversations when users enter specific sections of your site.

Best Practices

  • Debounce rapid calls — Avoid calling methods in quick succession
  • Add delays before reset — Give users time to read the final response
  • Respect dismissals — Don’t immediately reopen a closed chat bubble
  • Use contextual triggers — Open chat at moments when help is most relevant

Next Steps

Event Listeners

Learn to listen for and respond to chat events in real-time

Custom Initial Messages

Create dynamic, personalized initial messages for users

Floating Initial Messages

Display floating messages over the chat bubble