Skip to navigation
Calling

user_event

View as MarkdownOpen in Claude

Allows the user to set and send events to the connected client on the call. This is useful for triggering actions on the client side. Commonly used with the browser-sdk. Each user_event method sends one event, whose payload is the event object.

On an unanswered inbound call, user_event first attempts to answer the call before sending the event. Outbound calls and calls that are already answered aren’t answered again.

user_event
objectRequired

An object that accepts the following properties.

Properties

user_event.event
object | stringRequired

The payload of one custom event: an object that can contain any JSON values. Instead of an object, you can pass a SWML variable reference, such as ${my_event}, that resolves to an event object.

Event Object

The event object is sent to the client as the payload of a single event of type user_event. To send several events, use several user_event methods.

Variable references in the payload’s string values, including strings inside nested objects and arrays, are expanded before the event is sent. Object keys aren’t expanded.

SignalWire adds call details such as call_id, node_id, and segment_id at the top level of the payload, so top-level fields aren’t guaranteed to arrive unchanged. Put your custom data under your own key, as in the examples below, to avoid name collisions.

The client can listen for these events using the on-method.

Examples

Send a custom event to the client

version: 1.0.0
sections:
main:
- user_event:
event:
myCustomEvent: 'Hello, world!'
- play:
url: 'say: Custom event sent.'

Send one event with multiple payload fields

The eventA and eventB fields below are both part of a single event’s payload.

version: 1.0.0
sections:
main:
- user_event:
event:
eventA:
foo: bar
eventB:
count: 42
active: true
- play:
url: 'say: Event sent.'

Send an event payload stored in a variable

version: 1.0.0
sections:
main:
- set:
order_update:
order:
id: '1234'
status: shipped
caller: '${call.from}'
- user_event:
event: '${order_update}'