Actions
Available actions for trigger rules
Actions
Actions define what happens when a trigger rule’s conditions are met. The @repo/trigger-rules
package supports various action types that can be performed in response to events.
Action Structure
An action has the following structure:
Each action type has its own set of required and optional properties.
Available Action Types
Email Actions
Send emails to users or administrators:
Property | Description | Required |
---|---|---|
template | Email template ID | Yes |
recipient | Email recipient | Yes |
subject | Email subject | No (can be defined in template) |
data | Template variables | No |
cc | Carbon copy recipients | No |
bcc | Blind carbon copy recipients | No |
Notification Actions
Send notifications to users or teams:
Property | Description | Required |
---|---|---|
target | Notification target (user ID, role, or team) | Yes |
channel | Notification channel (slack, email, in-app) | Yes |
message | Notification message | Yes |
priority | Notification priority (low, medium, high) | No |
data | Additional data for the notification | No |
Webhook Actions
Send HTTP requests to external services:
Property | Description | Required |
---|---|---|
url | Webhook URL | Yes |
method | HTTP method (GET, POST, PUT, DELETE) | Yes |
headers | HTTP headers | No |
payload | Request payload | No |
timeout | Request timeout in milliseconds | No |
Function Actions
Execute a JavaScript function:
Property | Description | Required |
---|---|---|
name | Function name (must be registered) | Yes |
args | Function arguments | No |
Functions must be registered before they can be used:
Database Actions
Perform database operations:
Property | Description | Required |
---|---|---|
operation | Database operation (insert, update, delete, query) | Yes |
table | Database table name | Yes |
where | Condition for update/delete/query | Depends on operation |
data | Data for insert/update | Depends on operation |
returning | Fields to return | No |
Event Actions
Trigger another event:
Property | Description | Required |
---|---|---|
name | Event name | Yes |
payload | Event payload | Yes |
delay | Delay in milliseconds before triggering | No |
Log Actions
Log information for debugging or auditing:
Property | Description | Required |
---|---|---|
level | Log level (debug, info, warn, error) | Yes |
message | Log message | Yes |
data | Additional data to log | No |
Template Variables
Actions support template variables that are replaced with values from the event data or environment:
Event Data Variables
Access event data using the {{field.path}}
syntax:
Special Variables
Special variables provide access to system values:
Variable | Description | Example |
---|---|---|
{{now}} | Current timestamp | "timestamp": "{{now}}" |
{{rule.id}} | Current rule ID | "ruleId": "{{rule.id}}" |
{{rule.name}} | Current rule name | "ruleName": "{{rule.name}}" |
{{env.VARIABLE}} | Environment variable | "apiKey": "{{env.API_KEY}}" |
Internationalization Support
Actions can include internationalization support for messages and content:
The appropriate message will be selected based on the user’s locale or system default.
Custom Action Types
You can extend the rule engine with custom action types by registering them:
Action Execution
Actions are executed in the order they are defined in the rule. If an action fails, subsequent actions will still be executed unless you configure the rule to stop on failure.
To configure failure behavior:
Best Practices
- Keep actions focused - Each action should have a clear, specific purpose
- Use template variables - Make your actions dynamic with template variables
- Handle failures - Consider what should happen if an action fails
- Test thoroughly - Validate your actions with different inputs
- Use internationalization - Support multiple languages where appropriate
Examples
Send Welcome Email and Notify Sales Team
Update User Status and Log Activity
See Also
- Learn about Rule Management techniques
- Explore Testing Rules effectively
- See how to integrate with Trigger.dev