# Author trigger definitions

Separate reusable event code from per-instance transport, polling state and subscription setup.

Canonical URL: https://opennodeflow.dev/wiki/custom-triggers/
JSON reference: https://opennodeflow.dev/wiki/custom-triggers/index.json
Source snapshot: 2026-10-23

A trigger asset defines reusable code and typed outputs. A trigger instance is a node on a workflow whose saved entry settings select manual, webhook, schedule, poll or managed WebSocket transport. Publishing a trigger does not create a listener, configure a provider subscription or enable a canvas.

## Define the data contract

Create a Library asset of kind Trigger. Declare useful output types and write an async TypeScript/JavaScript function body using the same contract as a code node. A basic payload projection can be:

```ts
const payload = context.input;
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
  throw new Error('Expected an object payload');
}
return { payload };
```

The example requires an appropriate declared `payload` output. For a real provider, validate its exact event structure and expose named typed blocks rather than inventing fields that may not exist. Preserve unknown or optional data deliberately. Never hardcode credentials, webhook keys or account-specific identities into reusable code.

## Configure each instance

After inserting a trigger, configure its saved `node.trigger` entry kind and enabled state. Automatic starts require both the workflow master and the selected entry to be enabled. A trigger must be a root with no incoming wires. Several independent triggers can share one canvas; each accepted run selects one entry and skips unrelated roots.

Webhook delivery needs a correctly configured external sender and the installation's protected workflow key. A Ready state means the ONF entry is available, not that a remote provider is subscribed or authenticated. Follow the provider's exact subscription and event-version requirements.

## Polling without accidental repeats

Polling code can use node-local `context.state` for cursors or checkpoints. Return `{__skip:true}` when there is no new event. The built-in polling model does not automatically deduplicate arbitrary provider responses, so choose a stable event identity and an explicit cursor policy.

Checkpoint placement matters. Committing a trigger cursor before a downstream action means that later action may fail after the event is considered seen. Keeping it unchanged can allow repeated provider effects. Use durable storage/queue records when multiple steps need a durable claim and recovery decision.

Polling and interval schedules are bounded; cron uses the server timezone. Missed or busy schedule ticks are skipped rather than backfilled. A paused entry prevents new starts and does not cancel work already accepted.

## Long-lived connections

Managed WebSocket ownership belongs to the host entry settings, not to a child function that has returned. Do not claim a permanent subscription by opening a socket inside a short-lived code attempt. Reconnect, queue bounds and runtime dispatch remain transport behavior.

## Test the intended boundary

Use a synthetic manual payload to verify parsing, schemas, optional fields and skip behavior. Use an isolated installation to test transport admission and restart behavior. A successful library Test does not prove provider account permissions or subscription delivery.

Publish help explaining event version, output sockets, configuration, external setup, effects, cursor/checkpoint semantics and error/retry behavior. Existing graph instances keep their earlier immutable pin until explicitly upgraded. Continue with [trigger operation](/wiki/triggers/) and [versioning](/wiki/versioning/).

---

## Documentation provenance

- `docs/AUTHORING.md`
- `docs/TRIGGERS.md`
- `docs/WEBSOCKETS.md`

This page describes maintained source, not a live inventory or an authorization to perform actions.
