JavaScript API
Programmatic open, close, dark mode, and token refresh for the ept AI chat widget.
JavaScript API
Control the embedded widget from your page after window.eptAIConfig is set and the loader has run.
Prerequisites
<script>
window.eptAIConfig = {
accessToken: 'your-access-token-from-backend',
botName: 'Support Bot',
};
</script>
<script
src="https://assets.ept.ai/chatbot/loader.js"
data-track="stable"
async>
</script>
Full install: Quickstart.
Show and hide
window.eptAIConfig.show();
window.eptAIConfig.hide();
Use with initiallyHidden: true when a custom launcher should open the widget:
window.eptAIConfig = {
accessToken: 'your-token',
initiallyHidden: true,
};
document.getElementById('open-chat').addEventListener('click', () => {
window.eptAIConfig.show();
});
Open from URL
Add ?chatbot_state=open to any page URL to auto-open the widget, including when initiallyHidden is true.
https://example.com/docs/getting-started?chatbot_state=open
Dark mode
window.eptAIConfig.setDarkMode(true);
window.eptAIConfig.setDarkMode(false);
You can also set darkMode: true in the initial config object. CSS variable theming: Configuring the Design.
Refresh the access token
Access tokens expire after 24 hours. Update the config when your backend issues a new token:
async function refreshToken() {
const response = await fetch('/api/ept-token');
const { access_token } = await response.json();
window.eptAIConfig.accessToken = access_token;
}
// Example: refresh before expiry
setInterval(refreshToken, 23 * 60 * 60 * 1000);
Keep client_id on the server. See Security & tokens.
Update context at runtime
Assign new values on window.eptAIConfig before the next user message. The widget sends the current eptMetaData and related fields with each message:
window.eptAIConfig.eptMetaData = {
page: location.pathname,
section: 'pricing',
locale: 'en',
};
window.eptAIConfig.defaultQuestions = [
'How does pricing work?',
'Can I talk to sales?',
];
Details: Consent, analytics & page context and Context-Aware Chat.
API reference
| Call / field | Description |
|---|---|
window.eptAIConfig.show() | Show the widget |
window.eptAIConfig.hide() | Hide the widget |
window.eptAIConfig.setDarkMode(boolean) | Toggle dark theme |
window.eptAIConfig.accessToken = string | Replace the JWT used for chat |
?chatbot_state=open | Query param to open on load |
Configuration fields (botName, inline, parentDiv, etc.) are documented on Quickstart.