userEvent

View as MarkdownOpen in Claude

Send a custom user-defined event on the call. User events allow you to pass application-specific data through the RELAY event system. Other listeners on the same call can receive and react to these events.

Parameters

event
string | undefined

The event name or identifier.

The options type also accepts additional keys (& Record<string, unknown>), but only the event field is extracted and sent in the RPC call.

Returns

Promise<Record<string, unknown>> — Server response confirming the event was sent.

Example

1import { RelayClient } from '@signalwire/sdk';
2
3const client = new RelayClient({
4 project: process.env.SIGNALWIRE_PROJECT_ID!,
5 token: process.env.SIGNALWIRE_TOKEN!,
6 contexts: ['default']
7});
8
9client.onCall(async (call) => {
10 await call.answer();
11
12 // Send a custom event
13 const result = await call.userEvent({
14 event: 'customer_identified',
15 });
16 console.log(`User event sent: ${JSON.stringify(result)}`);
17});
18
19await client.run();