---
related_nodes: ["send_user_event", "workflow_result_trigger", "on_scheduled_event"]
---

# On User Event

Starts the workflow when a `send_user_event` step in this workspace sends an event with this key,
or any event when the filter is left empty.

`filter` is read when the workflow is installed, not per event, so it cannot carry a value that
varies between events. One key serves every event of its kind, and the per-event detail arrives in
`output.payload`.

## Outputs

Socket: `output`

| Field | Type | Description |
|-------|------|-------------|
| `key` | string | The key the event was sent with. |
| `payload` | any | The JSON payload the event carried. |
| `sent_at` | string | RFC 3339 time the event was sent. |

## Fields

- `filter` — optional. The exact event key to start on, such as `orders.changed`. Leave it empty to
  start on every event in the workspace; `output.key` then says which key started the run, for
  workflows that log, count or route events. There are no patterns, prefixes or wildcards.

```json
{ "on_user_event": { "filter": "orders.imported" } }
```

A filter follows the key rule of `send_user_event`: 1 to 64 characters, each a lowercase letter
`a`–`z`, a digit `0`–`9`, `.`, `_` or `-`, the first a letter or digit. A filter that breaks it
still saves, with a finding on `filter`:
`Event key "Orders Changed" is not allowed. A key is 1 to 64 characters: lowercase letters, digits, '.', '_' and '-', starting with a letter or digit.`
The workflow then does not install, with the same message.

## Runs

- Each event starts one run. Runs start in the order the events were sent: per key with a
  filter, in send order across keys without one. They run alongside each other and may finish in
  any order; an event arriving while an earlier run is still going starts its own run.
- An event sent while the workflow is disabled or not installed never starts a run, then or later.
- When the workspace's run rate limit holds a start back, the run starts once the limit allows it.
- Events belong to their workspace. An event with the same key in another workspace does not start
  this workflow.

## The payload

An event is a signal, not a delivery. Its payload says what happened in as few fields as it takes:
the id of the record that changed, or a small status. It never carries the data itself; whoever
hears the event reads what it needs from where that lives. A workflow that saves a note sends
`notes.saved` with `{ "document_id": "01M7BX3ZEQPHGZRWDXGXE2GF7Q" }`, not the note's text, and a
panel that hears `notes.saved` reads the note again through a workflow. The payload is capped at
1,024 characters, and an event sent to listening clients reaches every client listening on the
workspace, for every member of it.

## Avoid loops

A workflow may listen to a key it sends, and a trigger with no filter hears every key its own
workflow sends. Each send starts another run, so a workflow that does this unconditionally keeps
running, as fast as the workspace's run rate limit lets it, until it is disabled. Always check
`output.key` before sending. Never send, unconditionally, a key the same workflow listens to. A
workflow whose trigger has no filter must not send at all without checking the key first.

Set a filter whenever the workflow cares about one key: the trigger then never starts for other
keys, and run history holds no runs that only filtered an event out.

## Examples

### Hand work to another workflow

An "Import orders" workflow writes new rows to the Orders table, then a `send_user_event` step sends
`orders.imported` with `{ "count": 12 }`. A "Notify shipping" workflow starts here with filter
`orders.imported` and reads the new orders from the table with a **Table** step.

### A note that refreshes its panel

A "Save note" workflow sends `notes.saved` with `{ "document_id": "{{ input.id }}" }` and **Send
to listening clients** on. A panel showing the note hears it with
`verdalia.api.onEvent('notes.saved', …)` and reads the note again, and any workflow starting here
with filter `notes.saved` starts a run for the same event.

## Related

- `send_user_event` — sends the events this trigger receives.
- `workflow_result_trigger` — start when another workflow finishes.
- `on_scheduled_event` — start when a scheduled event comes due.
