Automations & Events
Relevant source files
The following files were used as context for generating this wiki page:
Automations provide a framework for building event-driven workflows within the Resend platform. These workflows execute specific actions automatically when triggered by defined events, allowing for complex multi-step communication logic.
The system uses "Events" as the primary trigger signals and "Automations" as the logical containers for steps and connections. Users manage these components through the resend automations and resend events command groups in the CLI.
Sources: src/commands/automations/index.ts:15-18, skills/resend-cli/references/workflows.md:209-211
Automation Architecture
Automations consist of two primary structures: Steps and Connections. Steps define the functional actions or logic gates, while connections define the execution path between those steps.
Step Types
Steps represent individual actions within a workflow.
- Trigger: Initiates the automation based on a specific event name.
- Delay: Pauses execution for a specified duration (e.g., "5m").
- Send Email: Dispatches an email, typically using a template.
- Wait for Event: Pauses the workflow until a specific event is received.
- Condition: Branches the workflow based on logical criteria.
Sources: src/commands/automations/create.ts:31, skills/resend-cli/references/workflows.md:223-225
Connection Types
Connections establish the flow logic between step keys.
- Default: Standard progression from one step to the next.
- Condition Met / Not Met: Used for branching logic after a
conditionstep. - Timeout: Follows a path if a
wait_for_eventstep exceeds its limit. - Event Received: Triggered when the expected event arrives during a
wait_for_eventstep.
Sources: src/commands/automations/create.ts:32, skills/resend-cli/references/automations.md:23
Workflow Logic Diagram
The following diagram illustrates a standard automation flow involving a trigger, a delay, and a conditional email send.
The diagram shows how connections link different step types to create a functional workflow.
Sources: skills/resend-cli/references/workflows.md:220-230, src/commands/automations/create.ts:31-32
Event Management
Events serve as the entry point for automations. You must define an event schema before sending events to trigger workflows.
Event Definitions
Events require a unique name and an optional JSON schema. The schema maps field names to types such as string, number, boolean, or date. Note that event names cannot start with the reserved resend: prefix.
Sources: skills/resend-cli/references/automations.md:104-107
Triggering Automations
To trigger an automation, you send an event using the resend events send command. This requires identifying the target contact via --contact-id or --email and providing a JSON --payload that matches the event's schema.
Sources: skills/resend-cli/references/automations.md:126-132, skills/resend-cli/references/workflows.md:240
Workflow Execution (Runs)
Each time an event triggers an automation, the system creates a Run. You can monitor these runs to inspect execution details and step-level history.
Run Lifecycle
A run progresses through various states depending on the success or failure of its constituent steps.
| Status | Description |
|---|---|
running | The workflow is currently processing steps or waiting in a delay. |
completed | The workflow reached an end node successfully. |
failed | An error occurred during step execution. |
cancelled | The run was manually stopped or superseded. |
Sources: src/commands/automations/runs/list.ts:20, skills/resend-cli/references/automations.md:85
Run Execution Sequence
The following sequence diagram shows the interaction between the CLI, the Resend API, and the automation engine.
This diagram demonstrates the asynchronous nature of event-triggered automation runs.
Sources: skills/resend-cli/references/workflows.md:234-243, src/commands/automations/runs/list.ts:50-55
Command Reference
Automation Management
Manage the lifecycle of automation definitions.
| Command | Key Parameters | Purpose |
|---|---|---|
create | --name, --steps, --connections, --file | Defines a new workflow. |
update | [id], --status | Enables or disables an automation. |
get | [id] | Retrieves full object including steps array. |
stop | [id] | Disables status and cancels active runs. |
duplicate | [id] | Copies an existing automation. |
Sources: src/commands/automations/create.ts:11-20, src/commands/automations/update.ts:13-17, skills/resend-cli/references/automations.md:52-65
Payload Structure
The resend automations create command supports a --file flag for complex payloads. This JSON file must contain the name, steps, and connections properties. Flags provided at the command line override values found within the file.
{
"name": "Onboarding Flow",
"status": "enabled",
"steps": [
{ "key": "start", "type": "trigger", "config": { "eventName": "user.onboarded" } },
{ "key": "send", "type": "send_email", "config": { "template": { "id": "tmpl_123" } } }
],
"connections": [
{ "from": "start", "to": "send", "type": "default" }
]
}
Sources: src/commands/automations/create.ts:25-30, skills/resend-cli/references/workflows.md:220-230
Summary
Automations and Events enable developers to construct sophisticated, stateful workflows that respond to user actions in real-time. By combining diverse step types—such as delays and conditions—with granular event schemas, the system facilitates automated communication cycles. The Resend CLI provides comprehensive tools to define these workflows, trigger them via events, and inspect the resulting execution runs for operational visibility.
Sources: src/commands/automations/index.ts:15-20, skills/resend-cli/references/automations.md:1-10