Builds custom trigger types for events iii does not handle natively. Use when integrating webhooks, file watchers, IoT devices, database CDC, or any external event source.
Comparable to: Custom event adapters, webhook receivers
Use the concepts below when they fit the task. Not every custom trigger needs all of them.
registerTrigger and unregisterTrigger callbacksid, function_id, and configiii.trigger({ function_id, payload: event }) to invoke the registered functionhttp, cron, durable:subscriber, state, stream, subscribeExternal event source (webhook, file watcher, IoT, CDC, etc.)
→ Custom trigger handler (registerTriggerType)
→ iii.trigger({ function_id, payload: event })
→ Registered function processes the event
| Primitive | Purpose |
|---|---|
registerTriggerType(id, handler) | Define a new trigger type with lifecycle hooks |
unregisterTriggerType(id) | Clean up a custom trigger type |
TriggerConfig: { id, function_id, config } | Configuration passed to the trigger handler |
iii.trigger({ function_id, payload: event }) | Fire the registered function when the event occurs |
See ../references/custom-triggers.js for the full working example — a custom trigger type that listens for external events and routes them to registered functions.
Also available in Python: ../references/custom-triggers.py
Also available in Rust: ../references/custom-triggers.rs
Code using this pattern commonly includes, when relevant:
registerWorker(url, { workerName }) — worker initializationregisterTriggerType(id, { registerTrigger, unregisterTrigger }) — define the custom triggerregisterTrigger(config) — called by iii when a function subscribes to this trigger typeunregisterTrigger(config) — called by iii when a function unsubscribesiii.trigger({ function_id: config.function_id, payload: eventPayload }) — fire the target functionunregisterTrigger (close connections, remove listeners, clear intervals)const logger = new Logger() — structured loggingUse the adaptations below when they apply to the task.
file-watcher, mqtt, db-cdc)registerTrigger, start the listener (open socket, poll endpoint, subscribe to topic)unregisterTrigger, tear down the listener to avoid resource leaksconfig.id for clean unregistrationiii.trigger({ function_id, payload: event })iii-http-endpoints.iii-cron-scheduling.iii-queue-processing.iii-custom-triggers when iii has no built-in trigger type for the event source.iii-custom-triggers in the iii engine.