Sagen AI JavaScript Client SDK - Reference Guide

Events

Overview

Sagen Assistants allow you to register event handlers for various events that occur during the execution of the assistant. These events provide a variety of information, but the main reason to listen for events is to capture and act on metadata in responses.

Event Listening

1 sagen('on', 'sagen-avatar-message-received', ({ message }) => {
2    // do something with message.metadata
3 });

The above code will be triggered on every message received from the assistant. This would be where a developer could capture metadata from the assistant’s response and connect this data to their existing application. For example, if the metadata contained an id for a product, the developer could use this information to display an image of the product to the user or open a tab containing detailed product informaiton.

Event Types

Here is the complete list of events that are currently supported:

Event Name Description
sagen-avatar-asked desc
sagen-avatar-message-began desc
sagen-avatar-message-received desc
sagen-avatar-message-ended desc
sagen-start-clicked desc
sagen-avatar-ready desc
sagen-avatar-loaded desc
sagen-mic-activated desc
sagen-keyboard-activated desc
sagen-recording-began desc
sagen-recording-ended desc
sagen-talk-aborted desc
sagen-talk-muted desc
sagen-talk-unmuted desc
sagen-caption-enabled desc
sagen-caption-disabled desc
sagen-webgl-lostcontext | desc