Skip to main content
Control your website chat interface from your own code: open and close it, reset conversations, and change its options at runtime.

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.

openConversation(conversationId)

Switches the chat to an existing conversation from the user’s Recent chats.
string
required
The conversation’s ID, for example from User Conversations. The conversation must belong to the current user, or the chat can’t load it.
It doesn’t open the Chat Bubble. Call open() too if you want it shown. If you identify the user, the switch waits until identification finishes.

Runtime Options

Override a bounded set of your AI agent’s configured options for the current page load: the Chat Bubble’s display name, bubble text, 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. In addition, set runtime-only options that have no dashboard equivalent: dictation-only mode, dictation silence timeout, dictation waveform color, hiding the actions menu and turning off Widget click tracking. You can also set a background image behind the chat, which overrides the one saved in the dashboard. None of these are persisted either: reloading the page or calling resetOptions clears them.

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.
string
Overrides the text shown beside the icon in the floating Chat Bubble. Maximum 40 characters, and long labels clip on narrow screens. A non-empty value shows the text even when Show text in the Chat Bubble is off in the dashboard; an empty string hides it even when that setting is on. The dashboard’s icon alignment still decides which side the icon sits on, so runtime code cannot move it. Reading direction follows the text itself, so a right-to-left label reads correctly on a left-to-right page.
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 AI 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.
boolean
When true, the message box keeps only the dictation button — the text area, send button, voice mode button and attachments button are all hidden, so the only way to compose a message is by speaking. If dictation is turned off for the agent, nothing is left to show and the whole message box disappears. Existing messages, suggested messages and the rest of the chat window are unaffected.
number
Stops dictation automatically after the user has been silent for this many milliseconds, then transcribes what was recorded, just as if they had pressed stop. Silence is only counted after the user starts speaking, so a user who hasn’t said anything yet is never cut off. Must be a positive integer. When unset, dictation runs until the user stops it or the maximum recording length is reached.
boolean
When true, hides the three-dots menu in the chat header, including start new chat, end chat, recent chats and tickets.
string
Sets the color of the waveform shown while the user dictates, as a hex color such as "#FF0000". When unset, the waveform uses the theme’s default gray.
boolean
When true, the chat stops reporting which tracked Widget elements the visitor sees and uses. Use it when a visitor declines analytics in your consent tool. Elements shown while it is on are not counted. When unset, tracking is on.
string
Shows an image behind the chat, such as a faint logo watermark. Must be an https:// URL: http://, data: and relative URLs are rejected. The image sits behind the messages and never covers them or catches clicks, so opaque message bubbles hide the part of the image behind them. If the image fails to load, the background stays empty and Chatbase reports no error, so check the URL opens in a browser tab. The other backgroundImage* options take effect only while an image is shown, from this option or from the dashboard. When unset, the chat shows the background image saved in the dashboard, or none. See Background image.
string
How the image fills its area. One of:
  • "fit": the whole image is visible, scaled down to fit the area (CSS background-size: contain).
  • "crop": the image fills the area and the parts that don’t fit are cut off (CSS background-size: cover).
  • "scale": the image is sized to backgroundImageScale, or stretched to fill the area exactly when no scale is set.
When unset, the fit is "scale" if backgroundImageScale is set and "crop" otherwise.
string
The image’s size when the fit is "scale": one or two values, each in px, in % of the area, or auto. The first value is the width and the second the height, for example "40%" or "200px 80px". A single value sets the width and keeps the image’s proportions. Setting a scale without a fit uses the "scale" fit. With "fit" or "crop", the scale is ignored. Unitless numbers and calc() are rejected.
number
The image’s opacity, from 0 (invisible) to 1 (fully opaque). It applies to the image only: messages stay fully opaque. A value around 0.15 suits a watermark. When unset, the image is fully opaque.
string
Where the image sits in its area. One of "center", "top", "bottom", "left", "right", "top left", "top right", "bottom left" or "bottom right". When unset, the image is centered.
string
Which part of the chat window the image covers. One of:
  • "messages": behind the message list only. The image stays in place while the messages scroll.
  • "chat": behind the whole chat window, including the message input and footer. A header with a background color covers the part of the image behind it.
In voice mode, a "messages" image is hidden along with the message list, and a "chat" image stays behind the voice screen. When unset, the area is "messages".
Every change to the runtime overrides fires an optionsChanged event once the agent has re-rendered with it. Use it when you need to wait until an override is actually on screen — for example keeping a plain <iframe> hidden until dictationOnly has taken effect.
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 AI 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

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

Background image

The backgroundImage* options show an image behind the chat, such as a faint logo watermark. They work on the Chat Bubble and on Center Stage.
This shows the logo at 40% of the message area’s width, in its bottom right corner, at 15% opacity. Use a PNG or SVG with a transparent background so that only the logo shows. How backgroundImageFit and backgroundImageScale combine: Resetting backgroundImage removes the image but keeps the other background options, which apply again to the next image you set. To clear the image and its settings, reset all six keys. resetOptions() with no argument also clears them, along with every other runtime option.

Backgrounds saved in the dashboard

A background image can also be saved in the dashboard, under Display → Style → Background image for the Chat Bubble and for Center Stage. Every visitor sees the saved image without any code on your page. When a saved image exists, your page’s options override it one key at a time:
  • Each backgroundImage* option you set replaces the matching saved setting. Each option you don’t set keeps the saved setting, then falls back to the defaults above.
  • Setting backgroundImage replaces only the image. The saved fit, scale, opacity, position and area still apply to the new image unless you set them too.
  • resetOptions removes your page’s overrides and brings back the saved background. It can’t hide a saved image: to remove that, remove it in the dashboard.
When no image is saved, settings saved in the dashboard are ignored, and only the options your page sets apply.

Center Stage

Center Stage accepts the same six backgroundImage* options through its own script:
On a page that loads Center Stage but not the Chat Bubble, window.chatbase("setOptions", { ... }) reaches Center Stage too. How Center Stage differs from the Chat Bubble:
  • Only the six backgroundImage* keys are used. Other setOptions keys, such as footer, are ignored.
  • There are no per-field setters such as setBackgroundImage. Use setOptions.
  • An invalid value rejects the whole call, and the browser console shows [CHATBASE]: Invalid setOptions payload with the name of the invalid option. The Chat Bubble drops only the invalid option and applies the rest of the call.
  • Calls made before the script loads are applied once Center Stage is ready, and again after Center Stage reloads.
  • With backgroundImageArea: "chat", the image covers the Center Stage card: the header and the messages. The message box sits below the card, so the image doesn’t reach it.

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.

Controlling Without the Embed Script

If you embed the AI Agent as a plain <iframe>, window.chatbase doesn’t exist. The iframe accepts the same actions as messages posted to it, so send them there:
Wait for the iframe’s iframeReady message before posting. Anything sent before it is dropped.
Post to the agent’s origin rather than "*" where you can. See the Iframe Developer Guide for every message the iframe accepts.

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