Steps
Every step a workflow chain offers, from messages and delays to waits, branches, A/B cohorts, emitted events, custom actions and reusable fragments, with the rules each one follows.
The chain after workflow({...}) is the journey's steps, in order. Each method adds one node to the compiled IR and returns the builder, so a journey reads top to bottom. No step runs any logic when you call it: the chain only describes the journey, and the runner executes it later, one durable step per node. This page lists every method the builder has.
Overview
| Step | What it does |
|---|---|
.email(email.k, props) | Send an email |
.push(push.k, props, { devices? }) | Push to every device of the user, or only the latest; skipped if none |
.slack(slack.k, props) | Post to a Slack incoming webhook |
.discord(discord.k, props) | Post to a Discord webhook |
.sms(), .inApp(), .survey() | Message nodes with no built-in sender |
.prefer([first, second], props, { label? }) | One push and one email: the first the user is reachable on |
.delay('1 day') | Sleep; { min, max } sleeps a random time in between |
.timeWindow({ days?, between, tz? }) | Hold until inside a weekly window |
.waitUntil(condition, opts) | Wait for a condition, or time out |
.branch(label?, ...arms) | First-match branch; rejoins the main line afterwards |
.filter(condition, { reason? }) | Exit unless the condition holds |
.cohort(arms, { key? }) | Random A/B split; weights sum to 100 |
.exit(reason?) | End the journey; inside an arm, do not rejoin |
.sendEvent(e.x, payload?) | Emit an event, which may trigger another workflow |
.run(action, args) | Run a custom action inside a durable step |
.use(fragment) | Splice a flow(...) fragment in place |
Props and references
Message props, emitted payloads and action arguments take literals or references: u.name for a profile field, checkout.payload.value for a field of the triggering event. References resolve when the step runs, not when the workflow is defined, and the template's Zod schema parses the resolved props before the send.
A reference the user has no value for is passed as absent. A template that requires that prop refuses it: the message is not sent, and the journey fails at that step without a retry, with an error that names the field:
Either the data is missing, or the field should have been declared optional(...) in the contract so the types force the template to handle it.
Durations are typed literals: a number, a space, and second, minute, hour, day or week (singular or plural). '30 minutes', '1 day' and '2 weeks' compile; '1 huor' does not.
Messages
Every message step names a template definition, and that template's props schema types the call. A push template is not accepted where an email is, and a prop the schema does not declare, or a missing required one, is a type error. Templates and channels covers how templates are written and what each channel does at send time, and Channel examples shows each message step end to end.
.email()
Sends one email to the profile's email property, from the template's own from. A topic email is skipped while the user has opted out of its topic or of all email; a transactional one always goes. A user with no email gets no copy: it is settled undelivered as no_recipient, and the journey goes on.
.push()
Sends one copy per device the engine has registered for the user, or only to the most recently registered with { devices: 'latest' }. A user with no device is skipped, and so is a topic push the user opted out of. Each device's copy is its own durable step, so one device's refusal does not stop the others.
.slack()
Posts to a Slack incoming webhook. The webhook URL is a secret the template reads from the host's environment at send time. Slack posts have no topics and no opt-outs; they are for your team, not the user.
.discord()
Posts to a Discord webhook, the same way as .slack(). The template's content is a Discord webhook body (content, embeds, allowed_mentions, and so on).
.sms(), .inApp() and .survey()
These compile to message nodes but have no built-in sender and no template definitions. They take a hand-typed reference by key, and you deliver them with your own sender passed as the host's messages option:
An SMS reads its recipient from the profile's phone property.
.prefer()
Sends one message on the first channel the user can be reached on: one push and one email template, in priority order, rendered with the same props. Both templates must declare the same props type. Pass {} when they declare none.
prefer is sugar for the branch it compiles to, with the same IR, node ids and hash:
So the choice is made once, when the step is reached, and a first choice that fails to send retries as itself; it never falls through to the second channel. For templates with different props, or other channels, write the branch.
Time
.delay()
Sleeps for a fixed duration, or for a random duration between min and max. The random value is drawn once and checkpointed, so a replay does not roll again. A max shorter than min throws when the workflow is defined. After a delay the workflow's goal and exitWhen are checked.
.timeWindow()
Holds the journey until it is inside a weekly window, then continues; if it is already inside, it continues at once.
betweenis 24-hour time with leading zeros ('09:00', not'9:00'), and the window cannot cross midnight.daysdefaults to the whole week.tz: 'user'(the default) reads the profile'stime_zoneproperty, an IANA zone id, and falls back to UTC when it is missing or invalid. Any other string is a fixed IANA zone, checked when the workflow is defined.
A journey running with an accelerated clock skips time windows instead of waiting for them; see Testing.
.waitUntil()
Waits until a condition holds, then continues on the main line. If the timeout passes first, it does onTimeout:
'continue'(the default): carry on with the next step.'exit': end the journey.- A sub-flow: run those steps, then carry on with the next step.
A performed() inside a wait counts from the moment the wait began, so an event from before the wait cannot satisfy it. The wait is event-driven: it is woken by the user's events, by profile updates for profile conditions, and by device and opt-out changes for reachable(). It does not poll.
Flow control
.branch()
A first-match branch. Each arm is a [condition, sub-flow] tuple, and a bare sub-flow in last position is the default arm. The first arm whose condition holds runs; with no match and no default, the journey simply continues. After the arm finishes, execution rejoins the main line at the step after the branch. To end the journey inside an arm instead, finish it with .exit().
One primitive covers a two-way split (one arm and a default), a multi-way split (several arms) and an "only if" (a single arm). The optional first argument is a label: the node's name in Studio and in reports, not a jump target. There is no goto; looping goes through re-entry.
.filter()
A gate: the journey exits unless the condition holds, otherwise it continues. reason is the audit-log line and is metadata, so rewording it does not change the workflow's hash.
A filter step runs inside an instance that has already entered, so the entry counts against the re-entry policy. To keep users out before they enter, use the trigger's filter instead.
.cohort()
A random split for A/B tests. Weights sum to 100 and have at most two decimals. An arm without flow is a holdout that goes straight on. Arm names are letters, digits, _ and -, not starting with a digit, because they become part of node ids (and so, unlike labels, renaming an arm changes the hash).
Set key for any experiment whose results you intend to read. Bucketing then hashes userId:key instead of the node's position, so assignments survive edits that move the node, and the experiment keeps one identity across workflow versions.
.exit()
Ends the journey at once. Inside a branch arm it means "stop here, do not rejoin". The reason goes to the audit log and is metadata.
Data
.sendEvent()
Emits an event for the user, which may trigger another workflow. This is how workflows compose: the event comes from an e.xxx reference, so its payload is typed, and the call graph between workflows is visible in code. Only scalar fields can be sent (literals, u.xxx or trigger payload fields), and the event is checked against the contract like any ingested one. The step's identity travels as the event id, so a retried emit records the occurrence once.
A workflow that emits its own trigger event re-enters only as its reentry policy allows: not under never, and not under after_exit either, because the event arrives while the emitting instance still runs. concurrent with a cooldown is the shape of a periodic flow.
.run()
Runs a custom action: the escape hatch for side effects the built-in steps do not cover, such as syncing a CRM or issuing a coupon. action<A>(name, handler) defines it, and the type parameter types the arguments .run() accepts. Arguments may reference u.xxx and are resolved before the handler is called.
The IR records only the action's name and arguments, never its code. The implementation ships with the host and is registered through the config's actions; compileBundle checks that the action a workflow runs is the very object listed there, so two definitions cannot share a name. Because the code is not in the IR, a running journey always calls the current handler.
The handler runs inside a durable step: it is retried when it throws and checkpointed when it succeeds. It can therefore run more than once for one journey. Pass ctx.idempotencyKey (stable across replays and retries of this one node) to any external side effect so the other side can drop the duplicate. Throw a PermanentError (from sendwend/engine) when a retry would only repeat the failure.
.use() and flow()
flow() names a reusable fragment of steps. .use(fragment) splices it in place, and a fragment can also be a branch arm or an onTimeout. Each use gets its own copy, so one fragment can appear in several places and workflows. .use() is a composition step before compiling, not a node: the IR has no trace of it, and node ids are assigned as if the steps were written inline.
Rules for every step
- Sub-flow callbacks run once, synchronously, when the workflow is defined. An
asynccallback throws: its steps would be added after the ids were assigned. - Node ids are structural paths (
0,1,2.c0.1, ...). They name the durable steps, seed message idempotency keys and cohort buckets. Inserting a step shifts the ids of the steps after it, whichplan()reports as a run of changed nodes. See Versioning. - Labels and reasons are metadata. A branch label, a
preferlabel, an exit reason and a filter reason are excluded from the content hash. - Every method records its call site, so Studio can point from a node back to the line that wrote it. The location is metadata too.