Initial push of Plunk Next
This commit is contained in:
@@ -0,0 +1,211 @@
|
||||
---
|
||||
title: Advanced Workflow Automation
|
||||
description: Control workflow re-entry and pass execution context data
|
||||
---
|
||||
|
||||
## Workflow Re-Entry Control
|
||||
|
||||
Control whether contacts can enter the same workflow multiple times.
|
||||
|
||||
### Allow Re-Entry
|
||||
|
||||
Use when the workflow represents a repeating process:
|
||||
|
||||
```javascript
|
||||
{
|
||||
"name": "Weekly Newsletter",
|
||||
"triggerType": "EVENT",
|
||||
"triggerConfig": { "eventName": "newsletter.send" },
|
||||
"allowReentry": true // Contacts can re-enter
|
||||
}
|
||||
```
|
||||
|
||||
**When to use**:
|
||||
- Recurring campaigns (weekly newsletters)
|
||||
- Event-based sequences (cart abandoned)
|
||||
- Behavior triggers that can happen multiple times
|
||||
|
||||
**What happens**: Contact can have multiple active executions of the same workflow.
|
||||
|
||||
### Prevent Re-Entry (Default)
|
||||
|
||||
Use for one-time journeys:
|
||||
|
||||
```javascript
|
||||
{
|
||||
"name": "Onboarding Series",
|
||||
"triggerType": "EVENT",
|
||||
"triggerConfig": { "eventName": "user.signup" },
|
||||
"allowReentry": false // One-time only (default)
|
||||
}
|
||||
```
|
||||
|
||||
**When to use**:
|
||||
- User onboarding
|
||||
- Trial expiration
|
||||
- Welcome sequences
|
||||
|
||||
**What happens**: Contact can only enter once, even if the trigger fires again.
|
||||
|
||||
## Execution Context
|
||||
|
||||
Pass event-specific data when starting a workflow execution.
|
||||
|
||||
### Basic Example
|
||||
|
||||
```javascript
|
||||
// Start workflow with order-specific context
|
||||
fetch('/workflows/workflow_id/executions', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
contactId: 'contact_id',
|
||||
context: {
|
||||
orderNumber: 'ORD-12345',
|
||||
orderTotal: 299.99,
|
||||
deliveryDate: '2024-03-30'
|
||||
}
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
In your workflow email templates:
|
||||
|
||||
```html
|
||||
<p>Hi {'{{firstName}}'}!</p>
|
||||
<p>Order #{'{{orderNumber}}'}: ${'{{orderTotal}}'}</p>
|
||||
<p>Delivery: {'{{deliveryDate}}'}</p>
|
||||
```
|
||||
|
||||
The template accesses both contact data (`firstName`) and context data (`orderNumber`, `orderTotal`, `deliveryDate`).
|
||||
|
||||
### When to Use Context
|
||||
|
||||
**Use execution context for**:
|
||||
- Order-specific details
|
||||
- Event registration info
|
||||
- Session data
|
||||
- Campaign-specific values
|
||||
|
||||
**Update contact data for**:
|
||||
- Persistent user attributes
|
||||
- Cumulative metrics (total orders, lifetime value)
|
||||
- Segment-able fields
|
||||
|
||||
### Example: Order Confirmation Workflow
|
||||
|
||||
```javascript
|
||||
// Trigger workflow on purchase
|
||||
{
|
||||
"name": "Order Confirmation",
|
||||
"triggerType": "EVENT",
|
||||
"triggerConfig": { "eventName": "purchase.completed" },
|
||||
"allowReentry": true // Can purchase multiple times
|
||||
}
|
||||
|
||||
// Start execution with order context
|
||||
fetch('/workflows/order_workflow_id/executions', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
contactId: 'contact_id',
|
||||
context: {
|
||||
orderNumber: 'ORD-456',
|
||||
total: 199.99,
|
||||
trackingUrl: 'https://track.example.com/456'
|
||||
}
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
Workflow sends emails with order-specific details while tracking cumulative purchase data on the contact.
|
||||
|
||||
## Real-World Patterns
|
||||
|
||||
### Pattern 1: Trial Workflow
|
||||
|
||||
```javascript
|
||||
{
|
||||
"name": "14-Day Trial",
|
||||
"triggerType": "EVENT",
|
||||
"triggerConfig": { "eventName": "trial.started" },
|
||||
"allowReentry": false // Only trial once
|
||||
}
|
||||
|
||||
// Workflow steps:
|
||||
// Day 0: Welcome email
|
||||
// Day 7: Mid-trial check-in
|
||||
// Day 13: Upgrade reminder
|
||||
```
|
||||
|
||||
### Pattern 2: Cart Abandonment
|
||||
|
||||
```javascript
|
||||
{
|
||||
"name": "Cart Abandoned",
|
||||
"triggerType": "EVENT",
|
||||
"triggerConfig": { "eventName": "cart.abandoned" },
|
||||
"allowReentry": true // Can abandon multiple times
|
||||
}
|
||||
|
||||
// Pass cart data as context
|
||||
context: {
|
||||
cartTotal: 99.99,
|
||||
cartUrl: 'https://app.example.com/cart/abc'
|
||||
}
|
||||
```
|
||||
|
||||
### Pattern 3: Event Reminders
|
||||
|
||||
```javascript
|
||||
{
|
||||
"name": "Webinar Reminders",
|
||||
"triggerType": "EVENT",
|
||||
"triggerConfig": { "eventName": "webinar.registered" },
|
||||
"allowReentry": true // Can register for multiple webinars
|
||||
}
|
||||
|
||||
// Pass webinar details as context
|
||||
context: {
|
||||
webinarTitle: 'Email Automation Masterclass',
|
||||
webinarDate: '2024-04-10',
|
||||
webinarLink: 'https://zoom.us/j/12345'
|
||||
}
|
||||
```
|
||||
|
||||
## Monitoring Executions
|
||||
|
||||
Check workflow execution status:
|
||||
|
||||
```bash
|
||||
curl -X GET "/workflows/workflow_id/executions/execution_id" \
|
||||
-H "Authorization: Bearer sk_your_secret_key"
|
||||
```
|
||||
|
||||
Response shows step progress:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"id": "execution_id",
|
||||
"status": "active",
|
||||
"steps": [
|
||||
{
|
||||
"stepId": "step_1",
|
||||
"status": "completed",
|
||||
"completedAt": "2024-03-15T10:00:00Z"
|
||||
},
|
||||
{
|
||||
"stepId": "step_2",
|
||||
"status": "waiting",
|
||||
"waitingUntil": "2024-03-16T10:00:00Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Next Steps
|
||||
|
||||
- [Create workflows](/guides/workflows) to automate sequences
|
||||
- [Track events](/guides/events) to trigger workflows
|
||||
- [Set up segments](/guides/segments) for segment-based triggers
|
||||
Reference in New Issue
Block a user