What “writing a trigger” means
Workers don’t only call functions; they can also source events. When a worker advertises a trigger type (e.g.webhook, a custom schedule, or any external event source you implement), any
other worker can bind its functions to that type. The engine routes binding requests to your
trigger type’s handler, and your worker invokes the bound functions when the underlying event
fires.
This page is about authoring new trigger types from inside your worker. For invoking functions and
binding triggers to functions from the consumer side, see Using iii / Triggers.
Declare a trigger type
Inside the worker, register the trigger type once during startup. You pass anid and
description plus a handler with registerTrigger / unregisterTrigger callbacks. The engine
calls these whenever a consumer binds or unbinds a function against your trigger type, so your
worker can keep its own table of { trigger id → function id, config } bindings.
registerTriggerType returns a typed handle. Use it later to bind functions you own to this
trigger type, or to tear the type down.
- Node / TypeScript
- Python
- Rust
config and call-payload schemas, attach Pydantic, Zod, or schemars::JsonSchema types
to the registration in your language of choice. See each SDK’s reference for the exact builder.
Dispatch events to bound functions
There is no special “fire” API. When the underlying event source delivers something (an incoming HTTP request, a cron tick, a webhook hit), your worker looks up the bindings it stashed in itsregisterTrigger callback and invokes each bound function via worker.trigger(...).
- Node / TypeScript
- Python
- Rust
config and optional
condition_function_id, then routes matching invocations to the bound function and returns the
result to the caller.
Unregister a trigger type
registerTriggerType returns a handle with an unregister() method that tears down the trigger
type at runtime. When the worker disconnects, all trigger types it advertised are removed
automatically and the engine stops routing events that depended on them.
- Node / TypeScript
- Python
- Rust
What goes in Worker Docs
The trigger type id, the shape of theconfig consumers pass when binding, the call-payload
shape your worker delivers to bound functions, the event ordering guarantees, and any
back-pressure or retry semantics belong in this worker’s Worker Docs so consumers know what to
pass when they call registerTrigger. Keep iii-level concepts (the trigger binding model itself,
condition gates) here; document the per-type specifics there.