> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# on

> Register an event listener on a call.

[events-section]: /docs/server-sdks/reference/python/relay/call#events

[relayevent]: /docs/server-sdks/reference/python/relay/events

Register a listener for events on this call. The handler is called each time
an event of the specified type is received. Handlers can be regular functions
or async coroutines.

## **Parameters**

**`event_type`** `str` — required

The event type string to listen for (e.g., `"calling.call.state"`,
`"calling.call.play"`). See the [Events section][events-section]
on the Call page for class-level events, or individual method pages for
method-specific events.

---

**`handler`** `Callable[[RelayEvent], Any]` — required

Function or coroutine to invoke when the event fires. Receives a
[`RelayEvent`][relayevent] instance.

---

## **Returns**

`None`

## **Example**

```python {9,14,20}
from signalwire.relay import RelayClient

client = RelayClient(
    project="your-project-id",
    token="your-api-token",
    contexts=["default"],
)

@client.on_call
async def handle_call(call):
    await call.answer()

    # Register a listener for play events
    call.on("calling.call.play", lambda event: print(f"Play state: {event.params.get('state')}"))

    # Register a listener for state changes
    def on_state_change(event):
        print(f"Call state changed: {event.params.get('call_state')}")

    call.on("calling.call.state", on_state_change)

    action = await call.play([{"type": "tts", "params": {"text": "Hello!"}}])
    await action.wait()

client.run()
```