Overview
Events enable your application to react dynamically to changes within user Context.
These events are triggered automatically when a relevant change occurs. You can subscribe to them by registering event listeners. This allows you to respond to changes as they happen in real-time.
Limitations
Please note the following:
- Events will only trigger for active subscriptions.
- Events will not be captured unless you listen for them.
Quick Start
- Start listening in the loop with
waitEvent
:
const eventQueue = await EndpointFactory.getEventQueue();
if (!listenForEventsPromise) {
listenForEventsPromise = eventQueue.waitEvent();
listenForEventsPromise.then(result => {
console.log("onEvent", result);
listenForEventsPromise = null;
listenForEvents(eventQueue);
}
)
}
- Subscribe to Tool (e.g. Thread) events:
await threadApi.subscribeForMessageEvents(threadId);
- Unsubscribe, if events no longer needed:
await threadApi.unsubscribeFromMessageEvents(threadId);