Automations
Relevant source files
The following files were used as context for generating this wiki page:
Automations manage sequences of actions that execute automatically based on defined triggers. This system allows you to create complex workflows involving email delivery, delays, conditional logic, and contact management.
Sources: src/Service/Automation.php:40-49, tests/Fixtures/Automation.php:1-10
Architecture and Components
The Automations module consists of a service layer that interacts with the Resend API to manage automation definitions and their execution history (runs).
Data Structure
An automation consists of high-level metadata, a series of discrete steps, and connections that define the execution flow between those steps.
The diagram shows the relationship between an automation and its constituent steps and connections.
Sources: src/Automation.php:12-21, tests/Fixtures/Automation.php:7-110
Step Types and Configurations
Steps represent individual actions or logic gates within the workflow.
| Step Type | Description | Key Configuration Options |
|---|---|---|
trigger | Initiates the automation based on an event. | event_name |
send_email | Dispatches an email using a template or raw content. | template, subject, from |
delay | Pauses execution for a specified period. | duration |
wait_for_event | Pauses execution until a specific event occurs or a timeout is reached. | event_name, timeout, filter_rule |
condition | Branches the workflow based on data rules. | field, operator, value |
contact_update | Modifies properties of the contact in the workflow. | first_name, unsubscribed, properties |
contact_delete | Removes the contact from the system. | N/A |
add_to_segment | Assigns the contact to a specific segment. | segment_id |
Sources: src/Service/Automation.php:44-48, tests/Fixtures/Automation.php:13-74
Execution Logic
Connections define the path between steps. A connection can be unconditional or dependent on the outcome of the previous step.
The flowchart illustrates a typical automation path including triggers, delays, and conditional branching.
Sources: tests/Fixtures/Automation.php:100-145
Connection Types
Connections determine how the automation engine transitions between steps:
default: Standard transition after a step completes.condition_met/condition_not_met: Branches used after aconditionstep.event_received/timeout: Branches used after await_for_eventstep.
Sources: src/Service/Automation.php:49, tests/Fixtures/Automation.php:124-138
Automation Runs
An Automation Run represents a single execution instance of an automation for a specific target. It tracks the progress and status of every step performed.
Run Lifecycle
A run moves through statuses such as started and completed. Each step within the run also maintains its own status and timestamps.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the run. |
status | string | Current state of the run (e.g., completed). |
started_at | string | ISO timestamp of when the run began. |
steps | array | List of executed steps with their specific outputs or errors. |
Sources: src/Automations/Run.php:11-17, tests/Fixtures/Automations/Run.php:5-15
API Service Methods
The Resend\Service\Automation class provides methods to manage the lifecycle of automations and access their runs.
The sequence diagram details the interaction between the PHP client and the Resend API for creating automations and fetching run history.
Sources: src/Service/Automation.php:40-63, src/Service/Automations/Run.php:30-43
Management Actions
- Duplicate: Creates a copy of an existing automation. Sources: src/Service/Automation.php:116-123
- Stop: Immediately halts an active automation. Sources: src/Service/Automation.php:130-137
- Update: Modifies the steps, connections, or status of an existing automation. Sources: src/Service/Automation.php:87-101
Summary
The Automations module enables the orchestration of complex, event-driven communication workflows. By combining diverse step types—ranging from email delivery to conditional logic—and tracking detailed execution via Automation Runs, it provides a robust framework for automated contact engagement.
Sources: src/Service/Automation.php, src/Automations/Run.php