-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai-powered-lead-generation-pipeline.workflow.json
More file actions
349 lines (349 loc) · 11.6 KB
/
Copy pathai-powered-lead-generation-pipeline.workflow.json
File metadata and controls
349 lines (349 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
{
"name": "Outscraper - AI-powered lead generation pipeline",
"nodes": [
{
"parameters": {},
"id": "ff791f2a-b102-467b-9eaf-3b5db012e5e7",
"name": "Manual Trigger",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
-112,
208
]
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "industry",
"name": "industry",
"type": "string",
"value": "dentists"
},
{
"id": "location",
"name": "location",
"type": "string",
"value": "Austin, TX"
},
{
"id": "lead_limit",
"name": "lead_limit",
"type": "number",
"value": 20
}
]
},
"options": {}
},
"id": "9c060b1e-bf10-42e6-99ac-c22adc115e8f",
"name": "Set Search Criteria",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
112,
208
],
"notesInFlow": true,
"notes": "Change industry, location, and lead_limit before running."
},
{
"parameters": {
"query": "={{$json.industry + ' in ' + $json.location}}",
"limit": "={{$json.lead_limit}}",
"requestOptions": {}
},
"id": "2f4f5648-bab0-4fb7-9bd2-611b6cd2a80e",
"name": "Outscraper - Google Maps Search",
"type": "n8n-nodes-outscraper.outscraper",
"typeVersion": 2,
"position": [
352,
208
],
"credentials": {
"outscraperApi": {
"id": "8AvSJfwIww0gbyf7",
"name": "Outscraper account"
}
}
},
{
"parameters": {
"jsCode": "function isBusinessRecord(value) {\n return Boolean(\n value &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n (value.name || value.title || value.business_name || value.place_id || value.google_id || value.location_link)\n );\n}\n\nfunction collectBusinessRecords(value, output = []) {\n if (!value) return output;\n\n if (Array.isArray(value)) {\n for (const item of value) {\n collectBusinessRecords(item, output);\n }\n return output;\n }\n\n if (isBusinessRecord(value)) {\n output.push(value);\n return output;\n }\n\n if (typeof value === 'object') {\n for (const key of ['data', 'results', 'items', 'businesses']) {\n if (key in value) {\n collectBusinessRecords(value[key], output);\n }\n }\n }\n\n return output;\n}\n\nfunction cleanWebsite(value) {\n if (!value || typeof value !== 'string') return '';\n\n try {\n return decodeURIComponent(value);\n } catch {\n return value;\n }\n}\n\nconst leads = $input.all().flatMap((item) => collectBusinessRecords(item.json));\n\nreturn leads\n .map((lead) => {\n const website = cleanWebsite(lead.site || lead.website || lead.url || lead.domain || '');\n return {\n json: {\n name: lead.name || lead.title || lead.business_name || '',\n website,\n domain_or_url: website,\n phone: lead.phone || lead.phone_number || '',\n address: lead.full_address || lead.address || '',\n rating: lead.rating || '',\n reviews: lead.reviews || lead.reviews_count || '',\n category: lead.category || lead.type || lead.subtypes || '',\n google_maps_url: lead.location_link || '',\n source: 'google_maps',\n raw: lead,\n },\n };\n })\n .filter((item) => item.json.name || item.json.website);"
},
"id": "fd399ca1-4067-470a-9623-cc8ccce16c85",
"name": "Normalize Lead Candidates",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
592,
208
]
},
{
"parameters": {
"resource": "emailsAndContacts",
"query": "={{$json.domain_or_url}}",
"additionalFields": {},
"requestOptions": {}
},
"id": "234101e2-89b7-4365-ad8c-9aa0cf9486d8",
"name": "Outscraper - Emails & Contacts",
"type": "n8n-nodes-outscraper.outscraper",
"typeVersion": 2,
"position": [
832,
208
],
"notesInFlow": true,
"credentials": {
"outscraperApi": {
"id": "8AvSJfwIww0gbyf7",
"name": "Outscraper account"
}
},
"notes": "Uses the website/domain from each Google Maps lead."
},
{
"parameters": {
"jsCode": "function findEmail(value) {\n if (!value) return '';\n if (typeof value === 'string' && value.includes('@')) return value;\n if (Array.isArray(value)) {\n for (const item of value) {\n const email = findEmail(item);\n if (email) return email;\n }\n }\n if (typeof value === 'object') {\n for (const nested of Object.values(value)) {\n const email = findEmail(nested);\n if (email) return email;\n }\n }\n return '';\n}\n\nreturn $input.all().map((item) => {\n const email = findEmail(item.json);\n return {\n json: {\n ...item.json,\n email,\n },\n };\n}).filter((item) => item.json.email);"
},
"id": "42fa10d2-1960-47bc-b096-99d5a3d136b7",
"name": "Pick Best Email",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1072,
208
]
},
{
"parameters": {
"resource": "emailValidator",
"query": "={{$json.email}}",
"additionalFields": {},
"requestOptions": {}
},
"id": "6197f137-9d60-477f-8eac-f21f31f505ab",
"name": "Outscraper - Email Validator",
"type": "n8n-nodes-outscraper.outscraper",
"typeVersion": 2,
"position": [
1312,
208
],
"notesInFlow": true,
"credentials": {
"outscraperApi": {
"id": "8AvSJfwIww0gbyf7",
"name": "Outscraper account"
}
},
"notes": "Uses the Email Validator resource from this Outscraper node package."
},
{
"parameters": {
"jsCode": "return $input.all().map((item) => {\n const status = item.json.status || item.json.result || item.json.valid || '';\n return {\n json: {\n ...item.json,\n email_validation_status: status,\n crm_payload: {\n company: item.json.name,\n website: item.json.website,\n email: item.json.email,\n phone: item.json.phone,\n address: item.json.address,\n rating: item.json.rating,\n source: 'Outscraper Google Maps + Emails & Contacts',\n },\n },\n };\n});"
},
"id": "211f197d-db9c-40dc-80df-41a12ced6962",
"name": "Build CRM Payload",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1552,
208
]
},
{
"parameters": {
"promptType": "define",
"text": "=Score this B2B lead from Outscraper data. Use the connected structured output parser and return only the requested JSON shape. Include the lead identity fields so the CRM node can store the scored result. Input JSON: {{ JSON.stringify($json) }}",
"hasOutputParser": true,
"options": {
"enableStreaming": false
}
},
"id": "24f43c61-fd1f-4fd8-a4d9-1535b1366d0e",
"name": "AI Agent - Score Lead",
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 3.1,
"position": [
1792,
208
]
},
{
"parameters": {
"model": {
"__rl": true,
"value": "gpt-5.4-mini",
"mode": "list",
"cachedResultName": "gpt-5.4-mini"
},
"builtInTools": {},
"options": {}
},
"id": "38d57d83-04be-456e-87c8-c7789eaa0200",
"name": "OpenAI Chat Model - Score Lead",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1.3,
"position": [
1728,
416
],
"credentials": {
"openAiApi": {
"id": "cF6D8w13EQm9nSZt",
"name": "OpenAI account"
}
}
},
{
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n \"type\": \"object\",\n \"additionalProperties\": false,\n \"required\": [\n \"company\",\n \"website\",\n \"email\",\n \"phone\",\n \"lead_score\",\n \"score_reason\",\n \"recommended_next_step\"\n ],\n \"properties\": {\n \"company\": {\n \"type\": \"string\"\n },\n \"website\": {\n \"type\": \"string\"\n },\n \"email\": {\n \"type\": \"string\"\n },\n \"phone\": {\n \"type\": \"string\"\n },\n \"lead_score\": {\n \"type\": \"number\"\n },\n \"score_reason\": {\n \"type\": \"string\"\n },\n \"recommended_next_step\": {\n \"type\": \"string\"\n },\n \"risks\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n }\n }\n }\n}"
},
"id": "d6d5389e-3a82-4103-82c9-7bd63e9eb79b",
"name": "Structured Output Parser - Lead Score",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"typeVersion": 1.3,
"position": [
2000,
416
]
}
],
"pinData": {},
"connections": {
"Manual Trigger": {
"main": [
[
{
"node": "Set Search Criteria",
"type": "main",
"index": 0
}
]
]
},
"Set Search Criteria": {
"main": [
[
{
"node": "Outscraper - Google Maps Search",
"type": "main",
"index": 0
}
]
]
},
"Outscraper - Google Maps Search": {
"main": [
[
{
"node": "Normalize Lead Candidates",
"type": "main",
"index": 0
}
]
]
},
"Normalize Lead Candidates": {
"main": [
[
{
"node": "Outscraper - Emails & Contacts",
"type": "main",
"index": 0
}
]
]
},
"Outscraper - Emails & Contacts": {
"main": [
[
{
"node": "Pick Best Email",
"type": "main",
"index": 0
}
]
]
},
"Pick Best Email": {
"main": [
[
{
"node": "Outscraper - Email Validator",
"type": "main",
"index": 0
}
]
]
},
"Build CRM Payload": {
"main": [
[
{
"node": "AI Agent - Score Lead",
"type": "main",
"index": 0
}
]
]
},
"Outscraper - Email Validator": {
"main": [
[
{
"node": "Build CRM Payload",
"type": "main",
"index": 0
}
]
]
},
"AI Agent - Score Lead": {
"main": [
[]
]
},
"OpenAI Chat Model - Score Lead": {
"ai_languageModel": [
[
{
"node": "AI Agent - Score Lead",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Structured Output Parser - Lead Score": {
"ai_outputParser": [
[
{
"node": "AI Agent - Score Lead",
"type": "ai_outputParser",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1",
"binaryMode": "separate"
},
"versionId": "ac9e4c04-e582-49e5-8e3d-0f3bef305a62",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "bd51ba3d599fc63602ae14309acd27ef3912f3068784a786f28ba05657ba8dbb"
},
"id": "zklyd8A5I4RteP5y",
"tags": []
}