Contents

Send User Event

send_user_event · Nodes · Control

Sends a small event that On User Event triggers in this workspace's workflows receive, and optionally every client listening on the workspace

Send User Event#

Sends a small keyed event in the workspace. Every on_user_event trigger in the workspace whose filter is this key, and every one with no filter, starts a run for it. With broadcast_clients on, every client listening on the workspace also receives it, and an open panel listening on the key with verdalia.api.onEvent hears it.

key is a routing address. A trigger's filter is fixed when its workflow is installed, so put per-event detail in payload, not in the key: orders.{{ input.region }} reaches only triggers filtering on each key it renders to.

Inputs#

  • input — workflow data used for template interpolation.

Outputs#

Socket: output

Field Type Description
key string The key sent, as rendered.
payload any The payload sent; {} when the field is empty.
listeners number How many installed on_user_event triggers the event reached. Clients are not counted.

Fields#

  • key — required, templated. 1 to 64 characters, each a lowercase letter a–z, a digit 0–9, ., _ or -, the first a letter or digit. Nothing is lowercased for you: Orders.Changed is refused.
  • payload — JSON template, any JSON value. Empty sends {}.
  • broadcast_clients — Send to listening clients, off by default. Also sends the event to every client listening on this workspace, such as the web, desktop and mobile apps, as event.user.{key}. Panels hear it through the client they run in. It reaches clients, not particular windows, and there is no per-panel permission: every listening client of every member of the workspace receives it.
{
  "send_user_event": {
    "key": { "content": "notes.saved" },
    "payload": { "content": "{ \"document_id\": \"{{ input.id }}\" }" },
    "broadcast_clients": true
  }
}

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.

The cap is measured after templating, on the compact JSON that is sent, in characters: whitespace in the template does not count, é or an emoji counts once, and an escape such as \" counts as written.

Errors#

A literal key or payload that breaks a rule is a finding on its field when the workflow is saved; the workflow still saves. At run time the step fails with the same message, under its failure mode.

  • An empty key: Event key is required. A key that renders blank fails as a required field left empty.
  • A key that breaks the rule: 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 key is shown as written, cut short when long.
  • A payload that is not JSON: Event payload is not valid JSON.
  • A payload over the cap: Event payload is 1532 characters, which exceeds 1024. Send the id of what changed, and let the listener read the rest.
  • A template that cannot be filled in fails with the template's error.

An event nobody hears is not an error: the step succeeds with listeners: 0.

Delivery#

  • The event belongs to the workspace the run belongs to; nothing can send it to another workspace. orders.changed in another workspace is a different event.
  • Each listening trigger starts one run per event, in the order the events were sent, including events sent while earlier runs are still going. See on_user_event.
  • A trigger whose workflow is disabled or not installed, and a client or panel that is not listening, never receive the event, then or later.

Avoid loops#

A workflow may listen to a key it sends, and a workflow whose trigger has no filter hears every key it 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 which key started the run (output.key of on_user_event) before sending. Never send, unconditionally, a key the same workflow listens to. A workflow whose on_user_event has no filter must not send at all without checking the key first.

Examples#

A note that refreshes its panel#

A "Save note" workflow updates a document with Library (Update Document), then Send User Event with key notes.saved, payload { "document_id": "{{ input.id }}" } and Send to listening clients on. A panel showing the note calls verdalia.api.onEvent('notes.saved', …) and reads the note again when event.payload.document_id is the one it shows.

Hand work to another workflow#

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

Use subworkflow when the sender needs an answer from one workflow it knows. Send User Event returns at once, gets no answer, and starts every workflow listening on the key.

  • on_user_event — the trigger that starts a run for each event.
  • subworkflow — call one workflow and wait for its output.
  • schedule_event — an event for a later moment.

Inputs

  • inputRequired

Outputs

  • output

Configuration

FieldTypeRequiredDescription
keytext_blockYesThe key to send the event on, such as orders.changed
payloadtext_blockYesWhat changed, as small JSON: an id or a status. Empty sends {}
broadcast_clientsbooleanNoAlso send the event to every client listening on this workspace, such as the web, desktop and mobile apps
base_configrecordNoShared node configuration. failure_mode decides what a failure of this node does to the workflow; leave it at the default stop unless the workflow handles the failure itself on the node's error output (route_to_error) or the node is a rare emergency kill switch (stop_workflow).