|
| 1 | +import type { Automation } from '@objectstack/spec'; |
| 2 | +type Flow = Automation.Flow; |
| 3 | + |
1 | 4 | /** Campaign Enrollment — scheduled flow to bulk enroll leads */ |
2 | | -export const CampaignEnrollmentFlow = { |
| 5 | +export const CampaignEnrollmentFlow: Flow = { |
3 | 6 | name: 'campaign_enrollment', |
4 | 7 | label: 'Enroll Leads in Campaign', |
5 | 8 | description: 'Bulk enroll leads into marketing campaigns', |
6 | | - type: 'autolaunched', |
7 | | - triggerType: 'scheduled', |
8 | | - schedule: '0 9 * * 1', // Monday at 9am |
| 9 | + type: 'schedule', |
9 | 10 |
|
10 | 11 | variables: [ |
11 | 12 | { name: 'campaignId', type: 'text', isInput: true, isOutput: false }, |
12 | 13 | { name: 'leadStatus', type: 'text', isInput: true, isOutput: false }, |
13 | 14 | ], |
14 | 15 |
|
15 | | - steps: [ |
| 16 | + nodes: [ |
| 17 | + { id: 'start', type: 'start', label: 'Start (Monday 9 AM)', config: { schedule: '0 9 * * 1' } }, |
| 18 | + { |
| 19 | + id: 'get_campaign', type: 'get_record', label: 'Get Campaign', |
| 20 | + config: { objectName: 'campaign', filter: { id: '{campaignId}' }, outputVariable: 'campaignRecord' }, |
| 21 | + }, |
16 | 22 | { |
17 | | - id: 'get_campaign', |
18 | | - type: 'record_lookup', |
19 | | - label: 'Get Campaign', |
20 | | - objectName: 'campaign', |
21 | | - filter: { id: '{campaignId}' }, |
22 | | - outputVariable: 'campaignRecord', |
| 23 | + id: 'query_leads', type: 'get_record', label: 'Find Eligible Leads', |
| 24 | + config: { objectName: 'lead', filter: { status: '{leadStatus}', is_converted: false, email: { $ne: null } }, limit: 1000, outputVariable: 'leadList' }, |
23 | 25 | }, |
24 | 26 | { |
25 | | - id: 'query_leads', |
26 | | - type: 'record_query', |
27 | | - label: 'Find Eligible Leads', |
28 | | - objectName: 'lead', |
29 | | - filter: { status: '{leadStatus}', is_converted: false, email: { $ne: null } }, |
30 | | - limit: 1000, |
31 | | - outputVariable: 'leadList', |
| 27 | + id: 'loop_leads', type: 'loop', label: 'Process Each Lead', |
| 28 | + config: { collection: '{leadList}', iteratorVariable: 'currentLead' }, |
32 | 29 | }, |
33 | 30 | { |
34 | | - id: 'loop_leads', |
35 | | - type: 'loop', |
36 | | - label: 'Process Each Lead', |
37 | | - collection: '{leadList}', |
38 | | - itemVariable: 'currentLead', |
39 | | - steps: [ |
40 | | - { |
41 | | - id: 'create_campaign_member', |
42 | | - type: 'record_create', |
43 | | - label: 'Add to Campaign', |
44 | | - objectName: 'campaign_member', |
45 | | - fields: { |
46 | | - campaign: '{campaignId}', |
47 | | - lead: '{currentLead.id}', |
48 | | - status: 'sent', |
49 | | - added_date: '{NOW()}', |
50 | | - }, |
51 | | - }, |
52 | | - ], |
| 31 | + id: 'create_campaign_member', type: 'create_record', label: 'Add to Campaign', |
| 32 | + config: { |
| 33 | + objectName: 'campaign_member', |
| 34 | + fields: { campaign: '{campaignId}', lead: '{currentLead.id}', status: 'sent', added_date: '{NOW()}' }, |
| 35 | + }, |
53 | 36 | }, |
54 | 37 | { |
55 | | - id: 'update_campaign_stats', |
56 | | - type: 'record_update', |
57 | | - label: 'Update Campaign Stats', |
58 | | - recordId: '{campaignId}', |
59 | | - objectName: 'campaign', |
60 | | - fields: { num_sent: '{leadList.length}' }, |
| 38 | + id: 'update_campaign_stats', type: 'update_record', label: 'Update Campaign Stats', |
| 39 | + config: { objectName: 'campaign', filter: { id: '{campaignId}' }, fields: { num_sent: '{leadList.length}' } }, |
61 | 40 | }, |
| 41 | + { id: 'end', type: 'end', label: 'End' }, |
| 42 | + ], |
| 43 | + |
| 44 | + edges: [ |
| 45 | + { id: 'e1', source: 'start', target: 'get_campaign', type: 'default' }, |
| 46 | + { id: 'e2', source: 'get_campaign', target: 'query_leads', type: 'default' }, |
| 47 | + { id: 'e3', source: 'query_leads', target: 'loop_leads', type: 'default' }, |
| 48 | + { id: 'e4', source: 'loop_leads', target: 'create_campaign_member', type: 'default' }, |
| 49 | + { id: 'e5', source: 'create_campaign_member', target: 'update_campaign_stats', type: 'default' }, |
| 50 | + { id: 'e6', source: 'update_campaign_stats', target: 'end', type: 'default' }, |
62 | 51 | ], |
63 | 52 | }; |
0 commit comments