Lý thuyết
45 phút
Bài 8/15

Advanced Make Workflows

Xây dựng complex automation với Make - logic, branching, error handling

⚡ Advanced Make Workflows

Nâng cao kỹ năng automation với Make/Integromat.

Beyond Basic Workflows

Simple vs Advanced

Text
1Simple workflow:
2Trigger → Action → Action → Done
3
4Advanced workflow:
5Trigger → Router → Multiple paths
6 → Error handling
7 → Iterations
8 → Sub-scenarios
9 → Data transformation
10 → Conditional logic

Routers & Filters

Router Module

Text
1Split flow into multiple paths:
2
3 ┌→ Path 1: If order
4Incoming → Router┼→ Path 2: If question
5Message └→ Path 3: Default
6
7Each path:
8- Has filter condition
9- Executes independently
10- Can have different actions

Filter Setup

Text
1Filter conditions:
2- Contains: text contains "order"
3- Equals: status = "pending"
4- Greater than: amount > 100
5- Matches pattern: regex match
6- Is empty: field is blank
7- Exists: field has value

Multiple Conditions

Text
1AND: All must be true
2- status = "active"
3- AND amount > 50
4- AND type = "subscription"
5
6OR: Any can be true
7- source = "WhatsApp"
8- OR source = "Telegram"
9- OR source = "SMS"

Iterators & Aggregators

Iterator

Text
1Process arrays one item at a time:
2
3Input: [item1, item2, item3]
4
5 Iterator
6
7 item1 → Process
8 item2 → Process
9 item3 → Process
10
11Use for:
12- Process list of orders
13- Send multiple messages
14- Update multiple records

Aggregator

Text
1Combine multiple items back:
2
3 item1 →
4 item2 → Aggregator → Combined result
5 item3 →
6
7Types:
8- Array: Collect into array
9- Text: Join with separator
10- Numeric: Sum, average, count

Example: Process Orders

Text
1Scenario:
21. Get orders from API (returns array)
32. Iterator: For each order
43. Check inventory
54. Update status
65. Send notification
76. Aggregator: Collect results
87. Send summary report

Error Handling

Error Types

Text
1Common errors:
2- Connection failed
3- Invalid data
4- Rate limit
5- Timeout
6- Permission denied
7- Not found

Break Directive

Text
1Stop execution on error:
21. Add Error Handler
32. Select "Break"
43. Execution stops
54. Error logged
65. No further actions

Resume Directive

Text
1Continue despite error:
21. Add Error Handler
32. Select "Resume"
43. Log error
54. Continue to next module
65. Workflow completes

Commit Directive

Text
1Save progress on error:
21. Add Error Handler
32. Select "Commit"
43. Data up to error point saved
54. Execution stops
65. Can resume later

Rollback Directive

Text
1Undo changes on error:
21. Add Error Handler
32. Select "Rollback"
43. Undo committed changes
54. Clean state
65. Retry possible

Custom Error Handling

Text
1Handle specific errors:
2
3Router (error path):
4If error code = 429 (rate limit)
5 → Wait 60 seconds
6 → Retry
7
8If error code = 404 (not found)
9 → Create new record
10 → Continue
11
12Default:
13 → Log error
14 → Send alert
15 → Stop

Data Transformation

Built-in Functions

Text
1Text:
2- lower(text): Lowercase
3- upper(text): Uppercase
4- trim(text): Remove whitespace
5- replace(text, old, new): Replace
6- substring(text, start, length): Extract
7
8Numbers:
9- round(num, decimals)
10- floor(num), ceil(num)
11- formatNumber(num, format)
12
13Dates:
14- formatDate(date, format)
15- addDays(date, days)
16- parseDate(text, format)
17
18Arrays:
19- length(array)
20- first(array), last(array)
21- slice(array, start, end)
22- map(array, key)

JSON Operations

Text
1Parse JSON:
2- Use JSON module
3- parseJSON(text) function
4
5Create JSON:
6- Use JSON > Create JSON
7- Build object from variables
8
9Transform:
10- Extract specific fields
11- Restructure data
12- Filter arrays

Example: Transform API Response

Text
1API returns:
2{
3 "data": {
4 "orders": [
5 {"id": 1, "total": 100, "status": "pending"},
6 {"id": 2, "total": 200, "status": "shipped"}
7 ]
8 }
9}
10
11Transform:
121. Parse JSON
132. Access: data.orders
143. Filter: status = "pending"
154. Map: Extract only id and total
165. Result: [{"id": 1, "total": 100}]

Sub-Scenarios

Why Sub-Scenarios?

Text
1Benefits:
2- Reusable components
3- Cleaner main flow
4- Easier testing
5- Better organization

Creating Sub-Scenario

Text
11. Create new scenario
22. Use webhook as trigger
33. Build your logic
44. Return result with webhook response
5
6Main scenario:
71. Call sub-scenario via HTTP
82. Wait for response
93. Continue with result

Example: AI Processing Sub-Scenario

Text
1Sub-scenario: process_with_ai
2Input: {message, context}
3
41. Webhook trigger
52. OpenAI: Generate response
63. Store to database
74. Webhook response: {reply, tokens_used}
8
9Main scenarios call this sub-scenario
10when AI processing needed

Data Stores

Setup Data Store

Text
1Create persistent storage:
21. Go to Data Stores
32. Create new
43. Define structure:
5 - Key (unique identifier)
6 - Fields (columns)

Operations

Text
1Add/Update Record:
2- Add or replace by key
3- Upsert pattern
4
5Search Records:
6- Filter by conditions
7- Get multiple results
8
9Get Record:
10- Retrieve by key
11- Fast lookup
12
13Delete Record:
14- Remove by key
15- Clean up data

Use Cases

Text
1- Cache API responses
2- Track conversation state
3- Store user preferences
4- Rate limiting counters
5- Temporary data storage

Advanced Patterns

Retry Pattern

Text
1Handle transient failures:
2
31. Try action
42. If fails:
5 a. Increment counter
6 b. If counter < 3:
7 - Wait (exponential backoff)
8 - Retry
9 c. Else:
10 - Log failure
11 - Alert

Rate Limiting

Text
1Respect API limits:
2
3Before API call:
41. Get counter from data store
52. If counter > limit:
6 - Wait until reset
73. Else:
8 - Increment counter
9 - Make call

Deduplication

Text
1Prevent duplicate processing:
2
31. Generate hash of incoming data
42. Check data store for hash
53. If exists:
6 - Skip (already processed)
74. Else:
8 - Store hash
9 - Process

Scheduling

Schedule Options

Text
1Interval:
2- Every X minutes
3- Every X hours
4
5Time-based:
6- Every day at 9am
7- Every Monday
8- First of month
9
10On-demand:
11- Webhook trigger
12- Manual run

Scheduled AI Tasks

Text
1Example: Daily summary
2
3Schedule: Every day at 6pm
41. Get today's conversations
52. Send to AI: "Summarize trends"
63. Generate report
74. Email to team

Debugging

Execution History

Text
1Review past runs:
2- Input data
3- Output data
4- Errors
5- Duration
6- Module by module

Common Issues

Debug Tips
Text
1Data mapping errors:
2- Check data structure
3- Use get() with fallback
4- Validate inputs
5
6Rate limits:
7- Add delays between calls
8- Implement retry logic
9- Use batching
10
11Timeouts:
12- Optimize slow modules
13- Break into sub-scenarios
14- Increase timeout settings
15
16Memory issues:
17- Don't load huge arrays
18- Process in batches
19- Use streaming when possible

Performance Tips

Optimize Performance
Text
11. Minimize operations
2 - Combine where possible
3 - Remove unnecessary modules
4
52. Use filters early
6 - Filter before processing
7 - Skip irrelevant data
8
93. Batch operations
10 - Update many at once
11 - Reduce API calls
12
134. Cache responses
14 - Store in data store
15 - Set expiration
16
175. Parallel paths
18 - Independent actions parallel
19 - Use routers effectively

Bài Tập

Practice

Build Advanced Workflow:

  1. Create multi-path router
  2. Implement error handling
  3. Add data transformation
  4. Create sub-scenario
  5. Use data store for state
  6. Add retry logic
  7. Test all paths

Tiếp theo: Bài 9 - Stack AI