window.chatbase object with methods to control your chat widget programmatically.
Methods
open()
Opens the chat widget.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: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