Skip to main content
This page contains a full reference for the step function.

Parameters

string
required
Unique identifier for this step within the workflow.
Make sure you set a unique identifier for each step. Otherwise, the second step won’t execute and will reuse the output of the first step.
(opts: { attempt: number }) => T | Promise<T>
required
Function to execute. Receives the current attempt number.
object
Optional configuration object.

Methods

The following methods are available on each step:

listen

Put the workflow into listening mode, waiting for external events to resume:
Parameters:
string
required
The name of the step.

sleep

Pause workflow execution for a specified duration:
Parameters:
string
required
The name of the step.
number
required
Duration to sleep in milliseconds.

sleepUntil

Sleep until a specific date:
Parameters:
string
required
The name of the step.
Date | string
required
The date to sleep until.

fail

Mark the workflow as failed and stop execution:
Parameters:
string
required
Description of why the workflow failed.

abort

Immediately abort the workflow execution without marking it as failed:
Parameters: No parameters.

progress

Record a progress checkpoint without performing any action:
Parameters:
string
required
The name of the progress checkpoint.

waitForWorkflow

Wait for another workflow to complete before continuing:
Parameters:
string
required
The name of the step.
string
required
ID of the workflow to wait for.

executeWorkflow

Start another workflow and wait for it to complete:
Parameters:
string
required
The name of the step.
Workflow
required
The workflow instance to execute.
object
Input data for the workflow (typed based on workflow’s input schema).

map

Process an array of items in parallel with controlled concurrency:
Parameters:
string
required
The name of the map operation.
T[]
required
Array of items to process.
(item: T, opts: { i: number }) => Promise<U>
required
Function to process each item. Receives the item and its index.
object
Optional configuration object.

forEach

Process an array of items without collecting results:
Parameters:
string
required
The name of the forEach operation.
T[]
required
Array of items to process.
(item: T, opts: { i: number }) => Promise<void>
required
Function to process each item. Receives the item and its index.
object
Optional configuration object.

batch

Process items in sequential batches:
Parameters:
string
required
The name of the batch operation.
T[]
required
Array of items to process.
(batch: T[], opts: { i: number }) => Promise<void>
required
Function to process each batch. Receives the batch array and starting index.
object
Optional configuration object.

request

Request data from a conversation and wait for a response. Requires defining requests in the workflow:
Parameters:
string
required
The name of the request (must be defined in workflow’s requests field).
string
required
Message to display to the user describing what data is needed.
string
Optional custom name for the step. Defaults to the request name.