window.chatbase object with methods to control your chat widget programmatically.
Methods
open(options?)
Opens the chat widget. Optionally sends a message when it opens.A message to send automatically when the widget opens.
When
true, the sent message is hidden and the widget 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 widget.resetChat()
Clears the current conversation and starts a new session.Your widget configuration and custom initial
messages are preserved after
reset.
Examples
Combine these methods with event listeners to build powerful, context-aware chat experiences.Custom Buttons
Trigger widget actions from your own UI elements:Answer FAQ Questions
Turn static FAQ entries into live answers — open the widget with the question pre-filled: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
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 widget
- 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