Events
Events emitted by the Virbe web widget that your application can listen to for conversation messages, status changes, and user interactions.
The <virbe-plugin> element emits custom DOM events that your application can listen to. All events bubble and are composed (they cross shadow DOM boundaries), so you can listen on the element itself or on a parent.
Listening to Events
There are two ways to subscribe:
subscribeToEvent() (recommended)
Returns a subscription object with a clean unsubscribe() method:
const widget = document.querySelector('virbe-plugin');
const subscription = widget.subscribeToEvent('onConversationMessage', (event) => {
console.log(event.detail.action);
});
// Stop listening
subscription.unsubscribe();addEventListener()
Standard DOM event listening. Use removeEventListener() to unsubscribe:
function handleMessage(event) {
console.log(event.detail.action);
}
widget.addEventListener('onConversationMessage', handleMessage);
// Stop listening
widget.removeEventListener('onConversationMessage', handleMessage);Lifecycle Events
onInitialized
Fired when the widget has fully loaded and is ready to accept method calls.
- Payload: none
widget.subscribeToEvent('onInitialized', () => {
console.log('Widget is ready');
});onApiStatusChanged
Fired when the connection to the Virbe backend changes state.
- Payload:
{ action: ApiStatus }– The new connection status (e.g."connected","disconnected","reconnecting").
widget.subscribeToEvent('onApiStatusChanged', (event) => {
console.log('Connection status:', event.detail.action);
});onErrorNotice
Fired when an error occurs within the widget.
- Payload:
{ error: ErrorNotice }– Error details.
widget.subscribeToEvent('onErrorNotice', (event) => {
console.error('Widget error:', event.detail.error);
});Conversation Events
onConversationMessage
Fired for each message in the conversation (both user and virtual being messages).
- Payload:
{ action: ConversationMessageDto }– The full message object.
widget.subscribeToEvent('onConversationMessage', (event) => {
const message = event.detail.action;
console.log('Message:', message);
});onSignalAction
Fired when a signal action is received from the conversation engine. Signals are configured in the dashboard to trigger specific behaviors.
- Payload:
{ action: ConversationMessageSignalDto }– The signal data.
widget.subscribeToEvent('onSignalAction', (event) => {
const signal = event.detail.action;
if (signal.name === 'handover') {
// Trigger human handover flow
}
});onCustomMessageAction
Fired when a custom message action is received from the backend.
- Payload:
{ action: ConversationMessageCustomActionDto }– The custom action data.
onVariableStore
Fired when a variable is stored or updated in the conversation.
- Payload:
{ action: ConversationMessageVariableStoreDto }– The variable key-value pair.
widget.subscribeToEvent('onVariableStore', (event) => {
const { key, value } = event.detail.action;
console.log(`Variable stored: ${key} = ${value}`);
});onToolCall
Fired when the conversation engine triggers a tool/function call.
- Payload:
{ action: ConversationMessageToolCallDto }– The tool call details.
widget.subscribeToEvent('onToolCall', (event) => {
const toolCall = event.detail.action;
console.log('Tool called:', toolCall);
});onFlowAction
Fired when a flow transition occurs in the conversation engine.
- Payload:
{ action: ConversationFlowActionDto }– The flow action data.
Speech Events
onStartedSpeaking
Fired when the virtual being starts speaking.
- Payload: none
widget.subscribeToEvent('onStartedSpeaking', () => {
console.log('Being is speaking...');
});onEndedSpeaking
Fired when the virtual being finishes speaking.
- Payload: none
widget.subscribeToEvent('onEndedSpeaking', () => {
console.log('Being finished speaking');
});onInterruptSpeechClicked
Fired when the user clicks the interrupt button to stop the virtual being's speech.
- Payload: none
UI and Behavior Events
onUiAction
Fired when a UI action is requested by the conversation engine – for example, displaying buttons or cards for the user to interact with.
- Payload:
{ action: ConversationMessageUiActionDto }– Contains arrays of cards and buttons.
widget.subscribeToEvent('onUiAction', (event) => {
const { cards, buttons } = event.detail.action;
console.log('UI elements:', { cards, buttons });
});onBehaviourAction
Fired when a behavior action is triggered by the conversation engine.
- Payload:
{ action: ConversationMessageBehaviourActionDto }– The behavior action data.
onEngineEvent
Fired for low-level engine events from the backend.
- Payload:
{ event: ConversationMessageEngineEventDto }– The engine event data.
Event Reference Table
| Event | Payload | Description |
|---|---|---|
onInitialized | – | Widget fully loaded and ready |
onApiStatusChanged | { action: ApiStatus } | Backend connection status changed |
onErrorNotice | { error: ErrorNotice } | An error occurred |
onConversationMessage | { action: ConversationMessageDto } | Conversation message received |
onSignalAction | { action: ConversationMessageSignalDto } | Signal action from engine |
onCustomMessageAction | { action: ConversationMessageCustomActionDto } | Custom action from engine |
onVariableStore | { action: ConversationMessageVariableStoreDto } | Variable stored/updated |
onToolCall | { action: ConversationMessageToolCallDto } | Tool/function call triggered |
onFlowAction | { action: ConversationFlowActionDto } | Flow transition occurred |
onStartedSpeaking | – | Virtual being started speaking |
onEndedSpeaking | – | Virtual being finished speaking |
onInterruptSpeechClicked | – | User clicked interrupt |
onUiAction | { action: ConversationMessageUiActionDto } | UI elements (buttons/cards) displayed |
onBehaviourAction | { action: ConversationMessageBehaviourActionDto } | Behavior action triggered |
onEngineEvent | { event: ConversationMessageEngineEventDto } | Low-level engine event |
Cleanup Pattern
When subscribing to multiple events, store subscriptions and unsubscribe when no longer needed:
const subscriptions = [];
subscriptions.push(
widget.subscribeToEvent('onInitialized', () => { /* ... */ })
);
subscriptions.push(
widget.subscribeToEvent('onConversationMessage', (e) => { /* ... */ })
);
subscriptions.push(
widget.subscribeToEvent('onApiStatusChanged', (e) => { /* ... */ })
);
// Unsubscribe all at once
function cleanup() {
subscriptions.forEach((sub) => sub.unsubscribe());
}