HomeDocsSDK ReferenceEvent System
SDK Reference

Event System

The SDK uses an event-driven architecture to communicate back to your application.

Subscribing to Events

javascript
// Subscribe to a specific event
const removeListener = Querlo.on('message', (payload) => {
    console.log('Received message:', payload);
});

// To stop listening later:
removeListener();

Responding to Events (Return Pattern)

Some events allow you to send data back to the chatbot. When the chatbot sends an event that includes a varName in its payload, the SDK will automatically forward any value your listener returns as a chat variable.

You can return a value directly or a Promise.

javascript
// Sync return
Querlo.on('MY_CUSTOM_EVENT', (payload) => {
    return {
        theme: 'dark',
        user_id: 123
    };
});

// Async return
Querlo.on('MY_CUSTOM_EVENT', async (payload) => {
    const config = await fetch('/api/config').then(res => res.json());
    return config;
});

Common Events

EventPayloadDescription
`message``object`Triggered for every incoming `postMessage` from the chatbot.
`OPEN` / `CLOSE``object`Triggered when the chatbot UI state changes.