Automations Management
Relevant source files
The following files were used as context for generating this wiki page:
Automations Management provides a system for creating and executing automated workflows triggered by specific events. Users define sequences of steps, such as sending emails or adding delays, and connect them to form complex graph-based logic for lifecycle marketing and transactional flows.
Sources: resend/automations/_automation.py, examples/automations.py:1-40
Automation Components
The system represents an automation as a graph consisting of steps and connections.
Workflow Steps
Each step in an automation has a unique key, a specific type, and a configuration dictionary. Valid step types include triggers (which start the workflow), email delivery, time delays, and event waiting.
| Step Type | Description | Configuration Example |
|---|---|---|
trigger | Initiates the automation based on an event. | {"event_name": "user.created"} |
send_email | Sends an email using a template. | {"template": {"id": "tpl_123"}} |
delay | Pauses execution for a set duration. | {"duration": "30 minutes"} |
wait_for_event | Stops execution until a specific event occurs or times out. | {"event_name": "user.verified", "timeout": "1 hour"} |
Sources: resend/automations/_automation.py:27-50, examples/automations.py:84-110
Step Connections
Connections define the flow of execution between steps. They link a source step to a target step and can include specific transition logic, such as handling a successful condition or a timeout.
The diagram shows a multi-step flow where execution depends on event reception or timeout transitions.
Sources: examples/automations.py:112-117, resend/automations/_automation.py:17-25
API Implementation
The Automations class provides methods for managing the lifecycle of automation resources. The library supports both synchronous and asynchronous operations via request and AsyncRequest handlers.
Core Methods
- create / create_async: Initializes a new automation. You must include at least one trigger step in the configuration.
- get / get_async: Retrieves a specific automation by ID, including its steps and connections.
- update / update_async: Modifies existing automations. If you update steps, you must also provide the connections to maintain graph integrity.
- list / list_async: Returns a paginated list of automations, optionally filtered by
status. - stop / stop_async: Halts all active runs of a specific automation.
- duplicate / duplicate_async: Creates a copy of an existing automation.
Sources: resend/automations/_automations.py:228-390, resend/automations/_automations.py:61-75
Automation Execution (Runs)
Every time a trigger activates, the system generates an AutomationRun. This object tracks the execution status and the specific output or error of every step in the graph.
The diagram illustrates how an application retrieves historical and real-time execution data for a specific automation.
Sources: resend/automations/_automations.py:146-226, tests/automations_test.py:257-300
Data Models
The system utilizes specialized TypedDict structures to ensure type safety for API requests and responses.
| Model | Purpose | Key Fields |
|---|---|---|
Automation | Full automation object | id, name, status, steps, connections |
AutomationRun | Execution instance | status, started_at, completed_at, steps |
AutomationRunStep | Individual step result | key, status, output, error |
AutomationConnection | Graph link | from, to, type |
Sources: resend/automations/_automation.py:53-195
Status Enums
Automations and their runs utilize specific literal types to represent their state:
- AutomationStatus:
enabled,disabled. - AutomationRunStatus:
running,completed,failed,cancelled.
Sources: resend/automations/_automation.py:5-6
Summary
The Automations Management module enables the orchestration of event-driven workflows. By combining graph-based step definitions with robust execution tracking through Automation Runs, it allows developers to build complex communication logic that reacts to user behavior in real-time.