API Reference

Control the Sela widget programmatically and listen to events.

Global Object

The Sela widget exposes a global window.Sela object. You can use this to control the widget state and user session.

Methods

Sela.open()

Opens the chat widget programmatically.

javascript
// Open the widget (e.g., from a custom button)
document.getElementById('help-btn').addEventListener('click', () => {
  window.Sela.open();
});

Sela.close()

Closes the chat widget.

javascript
window.Sela.close();

Sela.identify(user)

Updates the current user's identity. This is useful for Single Page Applications (SPAs) when a user logs in without a page reload.

javascript
window.Sela.identify({
  email: 'alice@example.com',
  name: 'Alice Smith',
  user_hash: '...' // Optional, for secure mode
});

Events

Listen for widget events using standard window event listeners.

sela:ready

Fired when the widget is fully loaded and ready to accept commands.

javascript
window.addEventListener('sela:ready', () => {
  console.log('Sela widget is ready!');
  window.Sela.open();
});
sela:message_received

Fired when a new message arrives from the agent.

javascript
window.addEventListener('sela:message_received', (event) => {
  console.log('New message:', event.detail.text);
});