-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow.json
More file actions
619 lines (619 loc) · 31.4 KB
/
Copy pathworkflow.json
File metadata and controls
619 lines (619 loc) · 31.4 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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
{
"name": "Agentic Multi-Channel Triage & CRM Ops (Gmail/Telegram/WhatsApp → Multi-Provider AI Agent → Sheets/CRM/LINE/Telegram/WhatsApp/Drive)",
"nodes": [
{
"id": "trigger-gmail",
"name": "Gmail Trigger",
"type": "n8n-nodes-base.gmailTrigger",
"typeVersion": 1.2,
"position": [ -1200, 0 ],
"parameters": {
"pollTimes": { "item": [ { "mode": "everyMinute" } ] },
"filters": { "labelIds": [ "INBOX" ] },
"simple": false,
"options": { "downloadAttachments": true }
},
"credentials": { "gmailOAuth2": { "id": "REPLACE_ME", "name": "Gmail (support inbox)" } }
},
{
"id": "trigger-telegram",
"name": "Telegram Trigger",
"type": "n8n-nodes-base.telegramTrigger",
"typeVersion": 1.1,
"position": [ -1200, 560 ],
"disabled": true,
"parameters": { "updates": [ "message" ] },
"credentials": { "telegramApi": { "id": "REPLACE_ME", "name": "Telegram (support bot)" } },
"notes": "Optional inbound channel, OFF by default. Trigger nodes can't be env-gated the way action nodes below are -- n8n validates a trigger's credential at workflow-activation time, before any if-logic runs, so an unconfigured trigger would block activation entirely. To enable: re-enable this node and attach a real Telegram Bot API credential."
},
{
"id": "trigger-whatsapp",
"name": "WhatsApp Trigger",
"type": "n8n-nodes-base.whatsAppTrigger",
"typeVersion": 1,
"position": [ -1200, 760 ],
"disabled": true,
"parameters": { "updates": [ "messages" ] },
"credentials": { "whatsAppTriggerApi": { "id": "REPLACE_ME", "name": "WhatsApp (support number)" } },
"notes": "Optional inbound channel, OFF by default, same reason as the Telegram Trigger: n8n checks trigger credentials at activation time, so this can't be gated by a downstream env-var if. To enable: re-enable this node and attach a real WhatsApp Business Cloud API credential."
},
{
"id": "extract-fields",
"name": "Extract Email Fields",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [ -960, 0 ],
"parameters": {
"mode": "manual",
"assignments": {
"assignments": [
{ "name": "from", "type": "string", "value": "={{ $json.from.value[0].address }}" },
{ "name": "subject", "type": "string", "value": "={{ $json.subject }}" },
{ "name": "body", "type": "string", "value": "={{ $json.text }}" },
{ "name": "receivedAt", "type": "string", "value": "={{ $json.date }}" },
{ "name": "messageId", "type": "string", "value": "={{ $json.id }}" },
{ "name": "channel", "type": "string", "value": "email" },
{ "name": "replyTarget", "type": "string", "value": "={{ $json.from.value[0].address }}" }
]
}
}
},
{
"id": "extract-telegram",
"name": "Extract Telegram Fields",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [ -960, 560 ],
"parameters": {
"mode": "manual",
"assignments": {
"assignments": [
{ "name": "from", "type": "string", "value": "={{ $json.message.from.username ? '@' + $json.message.from.username : String($json.message.from.id) }}" },
{ "name": "subject", "type": "string", "value": "={{ 'Telegram message from ' + ($json.message.from.first_name || $json.message.from.username || 'user') }}" },
{ "name": "body", "type": "string", "value": "={{ $json.message.text }}" },
{ "name": "receivedAt", "type": "string", "value": "={{ new Date($json.message.date * 1000).toISOString() }}" },
{ "name": "messageId", "type": "string", "value": "={{ String($json.message.message_id) }}" },
{ "name": "channel", "type": "string", "value": "telegram" },
{ "name": "replyTarget", "type": "string", "value": "={{ String($json.message.chat.id) }}" }
]
}
},
"notes": "Maps the Telegram Bot API 'message' update shape. The bot must be added to the chat with permission to read messages."
},
{
"id": "extract-whatsapp",
"name": "Extract WhatsApp Fields",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [ -960, 760 ],
"parameters": {
"mode": "manual",
"assignments": {
"assignments": [
{ "name": "from", "type": "string", "value": "={{ $json.messages[0].from }}" },
{ "name": "subject", "type": "string", "value": "WhatsApp message" },
{ "name": "body", "type": "string", "value": "={{ $json.messages[0].text?.body || '' }}" },
{ "name": "receivedAt", "type": "string", "value": "={{ new Date(Number($json.messages[0].timestamp) * 1000).toISOString() }}" },
{ "name": "messageId", "type": "string", "value": "={{ $json.messages[0].id }}" },
{ "name": "channel", "type": "string", "value": "whatsapp" },
{ "name": "replyTarget", "type": "string", "value": "={{ $json.messages[0].from }}" }
]
}
},
"notes": "Maps the WhatsApp Business Cloud API webhook shape (messages[0]). Exact field paths depend on the n8n WhatsApp Trigger node version — not yet verified against a live webhook payload, check before going live."
},
{
"id": "normalize-inbound",
"name": "Normalized Inbound",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [ -820, 0 ],
"parameters": {},
"notes": "Common junction for all three inbound channels. Downstream nodes reference $('Normalized Inbound') instead of a channel-specific node, so the same reference resolves no matter which channel triggered this execution."
},
{
"id": "list-attachments",
"name": "List Attachments",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [ -960, 200 ],
"parameters": {
"mode": "runOnceForAllItems",
"jsCode": "// Gmail Trigger puts each attachment on its own binary key: attachment_0, attachment_1, ...\n// Fan out one n8n item per attachment so the loop below can upload them individually.\n// (Gmail-only for now — Telegram/WhatsApp media attachments are not yet wired into this branch.)\nconst results = [];\nfor (const item of $input.all()) {\n const binaryKeys = Object.keys(item.binary || {}).filter((k) => k.startsWith('attachment_'));\n for (const key of binaryKeys) {\n results.push({\n json: {\n messageId: item.json.id,\n subject: item.json.subject,\n fileName: (item.binary[key] && item.binary[key].fileName) || key\n },\n binary: { data: item.binary[key] }\n });\n }\n}\nreturn results;"
}
},
{
"id": "loop-attachments",
"name": "Loop Over Attachments",
"type": "n8n-nodes-base.splitInBatches",
"typeVersion": 3,
"position": [ -800, 200 ],
"parameters": {
"batchSize": 1,
"options": {}
}
},
{
"id": "check-drive-enabled",
"name": "Drive Configured?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [ -880, 340 ],
"parameters": {
"conditions": {
"options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
"conditions": [
{
"id": "drive-env-check",
"leftValue": "={{ $env.GOOGLE_DRIVE_FOLDER_ID }}",
"rightValue": "",
"operator": { "type": "string", "operation": "notEmpty", "singleValue": true }
}
],
"combinator": "and"
},
"options": {}
},
"notes": "Optional-integration gate, sits between List Attachments and Loop Over Attachments. True output (GOOGLE_DRIVE_FOLDER_ID set) proceeds to the Drive upload loop; false output skips straight to Attachments Done. Attachment handling turns itself on the moment the env var is set and a real Drive credential is attached -- no graph changes needed."
},
{
"id": "attachments-done",
"name": "Attachments Done",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [ -640, 60 ],
"parameters": {},
"notes": "End of the attachment-upload branch for this email. Nothing downstream needs this signal today; it's here so the branch has a visible terminus instead of a dangling 'done' output."
},
{
"id": "drive-upload-attachment",
"name": "Upload Attachment to Drive",
"type": "n8n-nodes-base.googleDrive",
"typeVersion": 3,
"position": [ -640, 260 ],
"parameters": {
"resource": "file",
"operation": "upload",
"name": "={{ $json.fileName }}",
"driveId": { "mode": "list", "value": "My Drive" },
"folderId": { "mode": "id", "value": "={{ $env.GOOGLE_DRIVE_FOLDER_ID }}" },
"binaryPropertyName": "data",
"options": {}
},
"onError": "continueRegularOutput",
"credentials": { "googleDriveOAuth2Api": { "id": "REPLACE_ME", "name": "Google Drive" } },
"notes": "Optional integration, gated by the 'Drive Configured?' IF node upstream -- if GOOGLE_DRIVE_FOLDER_ID isn't set, this node is never reached, so the placeholder credential is never exercised."
},
{
"id": "log-attachment-sheet",
"name": "Log Attachment to Sheet",
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 4.5,
"position": [ -480, 260 ],
"parameters": {
"operation": "append",
"documentId": { "value": "REPLACE_WITH_SHEET_ID", "mode": "id" },
"sheetName": { "value": "Attachments", "mode": "name" },
"columns": {
"mappingMode": "defineBelow",
"value": {
"timestamp": "={{ $now.toISO() }}",
"messageId": "={{ $('List Attachments').item.json.messageId }}",
"subject": "={{ $('List Attachments').item.json.subject }}",
"fileName": "={{ $('List Attachments').item.json.fileName }}",
"driveLink": "={{ $json.webViewLink ?? '' }}"
}
}
},
"notes": "One row per attachment, in a separate 'Attachments' tab from the main ops Log — correlate back to the email via messageId. Feeds back into Loop Over Attachments to process the next attachment.",
"credentials": { "googleSheetsOAuth2Api": { "id": "REPLACE_ME", "name": "Google Sheets" } }
},
{
"id": "lm-chat",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1.2,
"position": [ -900, 260 ],
"parameters": { "model": "gpt-4o-mini", "options": { "temperature": 0.2 } },
"credentials": { "openAiApi": { "id": "REPLACE_ME", "name": "OpenAI" } },
"notes": "Primary model. Tried first."
},
{
"id": "lm-chat-gemini",
"name": "Google Gemini Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"typeVersion": 1,
"position": [ -900, 330 ],
"disabled": true,
"parameters": { "modelName": "models/gemini-1.5-flash", "options": { "temperature": 0.2 } },
"credentials": { "googlePalmApi": { "id": "REPLACE_ME", "name": "Google Gemini" } },
"notes": "Advanced/optional, OFF by default -- the default setup path is single-provider (OpenAI only, see SETUP.md). Re-enable this node and attach a real Google Gemini credential to add it as fallback #1 (tried automatically if OpenAI errors or is rate-limited). Credential type name may differ slightly by n8n version — check the node's credential picker."
},
{
"id": "lm-chat-claude",
"name": "Anthropic Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
"typeVersion": 1,
"position": [ -900, 400 ],
"disabled": true,
"parameters": { "model": "claude-3-5-sonnet-latest", "options": { "temperature": 0.2 } },
"credentials": { "anthropicApi": { "id": "REPLACE_ME", "name": "Anthropic" } },
"notes": "Advanced/optional, OFF by default, same reason as the Gemini node. Re-enable this node and attach a real Anthropic credential to add it as fallback #2 (tried only if both OpenAI and Gemini fail/are disabled). '-latest' is an Anthropic alias for the newest snapshot; pin to a dated model name in production for reproducibility."
},
{
"id": "memory-buffer",
"name": "Conversation Memory (per sender)",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"typeVersion": 1.3,
"position": [ -760, 260 ],
"parameters": {
"sessionIdType": "customKey",
"sessionKey": "={{ $('Normalized Inbound').item.json.from }}",
"contextWindowLength": 10
}
},
{
"id": "vector-tool",
"name": "Company KB Search (RAG tool)",
"type": "@n8n/n8n-nodes-langchain.vectorStoreQdrant",
"typeVersion": 1.1,
"position": [ -620, 260 ],
"parameters": {
"mode": "retrieve-as-tool",
"qdrantCollection": { "value": "company-kb", "mode": "list" },
"toolName": "search_company_kb",
"toolDescription": "Search internal FAQ, pricing, and policy documents to ground answers before replying to a customer. Always check this before answering a factual question.",
"topK": 4
},
"credentials": { "qdrantApi": { "id": "REPLACE_ME", "name": "Qdrant (KB)" } }
},
{
"id": "embeddings",
"name": "Embeddings (OpenAI)",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"typeVersion": 1.2,
"position": [ -620, 420 ],
"parameters": { "model": "text-embedding-3-small" },
"credentials": { "openAiApi": { "id": "REPLACE_ME", "name": "OpenAI" } }
},
{
"id": "crm-tool",
"name": "CRM Lookup (tool)",
"type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
"typeVersion": 1.1,
"position": [ -480, 260 ],
"parameters": {
"toolDescription": "Look up an existing CRM contact/deal by email address before drafting a reply, so the agent knows account history and open tickets.",
"method": "GET",
"url": "={{ $env.CRM_WORKER_BASE_URL + '/v1/contacts/lookup' }}",
"sendQuery": true,
"queryParameters": {
"parameters": [ { "name": "email", "value": "={{ $fromAI('email') }}" } ]
},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": { "httpHeaderAuth": { "id": "REPLACE_ME", "name": "CRM API Key" } }
},
{
"id": "output-parser",
"name": "Structured Output Parser",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"typeVersion": 1.2,
"position": [ -340, 420 ],
"parameters": {
"jsonSchemaExample": "{\n \"category\": \"billing | technical | sales | complaint | spam\",\n \"priority\": \"urgent | standard\",\n \"summary\": \"one-sentence summary for the ops log\",\n \"suggested_reply\": \"a drafted reply in the customer's language, grounded in KB/CRM lookups, or empty string if priority is urgent and a human should write it\",\n \"needs_human\": true\n}"
}
},
{
"id": "ai-agent",
"name": "AI Agent - Triage & Draft",
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 1.9,
"position": [ -700, 0 ],
"parameters": {
"promptType": "define",
"text": "={{ 'New inbound message (channel: ' + $json.channel + ').\\nFrom: ' + $json.from + '\\nSubject: ' + $json.subject + '\\nBody:\\n' + $json.body }}",
"hasOutputParser": true,
"options": {
"systemMessage": "You are the triage agent for a services company's shared inbox, which now receives messages from email, Telegram, and WhatsApp. For every message: (1) classify category and priority, (2) use search_company_kb for any factual/policy question before answering, (3) use the CRM lookup tool to check if the sender is an existing customer and whether they have open tickets, (4) if priority is 'urgent' (angry customer, payment failure, security concern, or explicit escalation request) do NOT draft a reply yourself — set needs_human=true and leave suggested_reply empty so a person handles it, (5) otherwise draft a concise, polite reply in the same language as the incoming message, matching the tone/length appropriate to the channel (email can be longer; Telegram/WhatsApp replies should be short and conversational), grounded only in what the KB/CRM tools returned — never invent policy details. Always return the structured JSON schema exactly."
}
},
"notes": "Default setup path is single-provider: only the OpenAI Chat Model is enabled, so the AI Agent just uses it directly. The Gemini and Claude chat model nodes are still wired in (same ai_languageModel connection, giving a 3-model fallback chain OpenAI → Gemini → Claude) but ship disabled -- re-enable them and attach real credentials for multi-provider failover. See SETUP.md."
},
{
"id": "route-priority",
"name": "Route by Category/Priority",
"type": "n8n-nodes-base.switch",
"typeVersion": 3.2,
"position": [ -440, 0 ],
"parameters": {
"rules": {
"values": [
{ "outputKey": "urgent", "conditions": { "conditions": [ { "leftValue": "={{ $json.output.priority }}", "rightValue": "urgent", "operator": { "type": "string", "operation": "equals" } } ] } },
{ "outputKey": "spam", "conditions": { "conditions": [ { "leftValue": "={{ $json.output.category }}", "rightValue": "spam", "operator": { "type": "string", "operation": "equals" } } ] } },
{ "outputKey": "standard", "conditions": { "conditions": [ { "leftValue": "={{ $json.output.priority }}", "rightValue": "standard", "operator": { "type": "string", "operation": "equals" } } ] } }
]
},
"options": { "fallbackOutput": "standard" }
}
},
{
"id": "route-reply-channel",
"name": "Route Reply by Channel",
"type": "n8n-nodes-base.switch",
"typeVersion": 3.2,
"position": [ -60, 40 ],
"parameters": {
"rules": {
"values": [
{ "outputKey": "email", "conditions": { "conditions": [ { "leftValue": "={{ $('Normalized Inbound').item.json.channel }}", "rightValue": "email", "operator": { "type": "string", "operation": "equals" } } ] } },
{ "outputKey": "telegram", "conditions": { "conditions": [ { "leftValue": "={{ $('Normalized Inbound').item.json.channel }}", "rightValue": "telegram", "operator": { "type": "string", "operation": "equals" } } ] } },
{ "outputKey": "whatsapp", "conditions": { "conditions": [ { "leftValue": "={{ $('Normalized Inbound').item.json.channel }}", "rightValue": "whatsapp", "operator": { "type": "string", "operation": "equals" } } ] } }
]
},
"options": { "fallbackOutput": "email" }
},
"notes": "Only reached for standard-priority messages (urgent ones skip drafting entirely). Sends the AI-drafted reply back on whichever channel the message came in on."
},
{
"id": "log-sheet",
"name": "Log to Ops Sheet",
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 4.5,
"position": [ -160, -160 ],
"parameters": {
"operation": "append",
"documentId": { "value": "REPLACE_WITH_SHEET_ID", "mode": "id" },
"sheetName": { "value": "Log", "mode": "name" },
"columns": {
"mappingMode": "defineBelow",
"value": {
"timestamp": "={{ $now.toISO() }}",
"channel": "={{ $('Normalized Inbound').item.json.channel }}",
"from": "={{ $('Normalized Inbound').item.json.from }}",
"subject": "={{ $('Normalized Inbound').item.json.subject }}",
"category": "={{ $json.output.category }}",
"priority": "={{ $json.output.priority }}",
"summary": "={{ $json.output.summary }}",
"needs_human": "={{ $json.output.needs_human }}"
}
}
},
"notes": "Attachment links are NOT joined in here — they land in the separate 'Attachments' sheet tab (Gmail only, see Log Attachment to Sheet), correlated by messageId.",
"credentials": { "googleSheetsOAuth2Api": { "id": "REPLACE_ME", "name": "Google Sheets" } }
},
{
"id": "gmail-draft",
"name": "Create Gmail Draft Reply",
"type": "n8n-nodes-base.gmail",
"typeVersion": 2.1,
"position": [ 80, -40 ],
"parameters": {
"resource": "draft",
"operation": "create",
"subject": "={{ 'Re: ' + $('Normalized Inbound').item.json.subject }}",
"emailType": "text",
"message": "={{ $json.output.suggested_reply }}",
"options": { "threadId": "={{ $('Normalized Inbound').item.json.messageId }}" }
},
"credentials": { "gmailOAuth2": { "id": "REPLACE_ME", "name": "Gmail (support inbox)" } }
},
{
"id": "telegram-reply",
"name": "Send Telegram Reply",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1.2,
"position": [ 80, 120 ],
"parameters": {
"resource": "message",
"operation": "sendMessage",
"chatId": "={{ $('Normalized Inbound').item.json.replyTarget }}",
"text": "={{ $json.output.suggested_reply }}"
},
"credentials": { "telegramApi": { "id": "REPLACE_ME", "name": "Telegram (support bot)" } }
},
{
"id": "whatsapp-reply",
"name": "Send WhatsApp Reply",
"type": "n8n-nodes-base.whatsApp",
"typeVersion": 1,
"position": [ 80, 220 ],
"parameters": {
"resource": "message",
"operation": "send",
"recipientPhoneNumber": "={{ $('Normalized Inbound').item.json.replyTarget }}",
"textBody": "={{ $json.output.suggested_reply }}"
},
"credentials": { "whatsAppApi": { "id": "REPLACE_ME", "name": "WhatsApp (support number)" } }
},
{
"id": "crm-ticket",
"name": "Create CRM Ticket (urgent)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [ -160, 220 ],
"parameters": {
"method": "POST",
"url": "={{ $env.CRM_WORKER_BASE_URL + '/v1/tickets' }}",
"sendBody": true,
"bodyParameters": {
"parameters": [
{ "name": "email", "value": "={{ $('Normalized Inbound').item.json.from }}" },
{ "name": "subject", "value": "={{ $('Normalized Inbound').item.json.subject }}" },
{ "name": "summary", "value": "={{ $json.output.summary }}" },
{ "name": "priority", "value": "high" },
{ "name": "channel", "value": "={{ $('Normalized Inbound').item.json.channel }}" }
]
},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": { "httpHeaderAuth": { "id": "REPLACE_ME", "name": "CRM API Key" } }
},
{
"id": "check-line-enabled",
"name": "LINE Configured?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [ -300, 340 ],
"parameters": {
"conditions": {
"options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
"conditions": [
{
"id": "line-env-check",
"leftValue": "={{ $env.LINE_OPS_GROUP_ID }}",
"rightValue": "",
"operator": { "type": "string", "operation": "notEmpty", "singleValue": true }
}
],
"combinator": "and"
},
"options": {}
},
"notes": "Optional ops-alert channel. Skipped entirely if LINE_OPS_GROUP_ID isn't set -- the placeholder LINE credential is never exercised, so no LINE account is needed unless you want this alert."
},
{
"id": "check-telegram-ops-enabled",
"name": "Telegram Ops Configured?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [ -300, 460 ],
"parameters": {
"conditions": {
"options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
"conditions": [
{
"id": "telegram-ops-env-check",
"leftValue": "={{ $env.TELEGRAM_OPS_CHAT_ID }}",
"rightValue": "",
"operator": { "type": "string", "operation": "notEmpty", "singleValue": true }
}
],
"combinator": "and"
},
"options": {}
},
"notes": "Optional ops-alert channel, independent of the Telegram Trigger -- get urgent-message pings in Telegram without turning on Telegram as an inbound channel. Skipped entirely if TELEGRAM_OPS_CHAT_ID isn't set."
},
{
"id": "check-whatsapp-ops-enabled",
"name": "WhatsApp Ops Configured?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [ -300, 580 ],
"parameters": {
"conditions": {
"options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
"conditions": [
{
"id": "whatsapp-ops-env-check",
"leftValue": "={{ $env.WHATSAPP_OPS_NUMBER }}",
"rightValue": "",
"operator": { "type": "string", "operation": "notEmpty", "singleValue": true }
}
],
"combinator": "and"
},
"options": {}
},
"notes": "Optional ops-alert channel, independent of the WhatsApp Trigger. Skipped entirely if WHATSAPP_OPS_NUMBER isn't set."
},
{
"id": "line-notify",
"name": "Notify Ops Team (LINE)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [ -160, 340 ],
"parameters": {
"method": "POST",
"url": "https://api.line.me/v2/bot/message/push",
"sendHeaders": true,
"headerParameters": { "parameters": [ { "name": "Content-Type", "value": "application/json" } ] },
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify({ to: $env.LINE_OPS_GROUP_ID, messages: [ { type: 'text', text: 'Urgent ' + $('Normalized Inbound').item.json.channel + ' message from ' + $('Normalized Inbound').item.json.from + ': ' + $json.output.summary } ] }) }}",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": { "httpHeaderAuth": { "id": "REPLACE_ME", "name": "LINE Channel Access Token" } }
},
{
"id": "telegram-notify",
"name": "Notify Ops Team (Telegram)",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1.2,
"position": [ -160, 460 ],
"parameters": {
"resource": "message",
"operation": "sendMessage",
"chatId": "={{ $env.TELEGRAM_OPS_CHAT_ID }}",
"text": "={{ 'Urgent ' + $('Normalized Inbound').item.json.channel + ' message from ' + $('Normalized Inbound').item.json.from + ': ' + $json.output.summary }}"
},
"credentials": { "telegramApi": { "id": "REPLACE_ME", "name": "Telegram (support bot)" } }
},
{
"id": "whatsapp-notify",
"name": "Notify Ops Team (WhatsApp)",
"type": "n8n-nodes-base.whatsApp",
"typeVersion": 1,
"position": [ -160, 580 ],
"parameters": {
"resource": "message",
"operation": "send",
"recipientPhoneNumber": "={{ $env.WHATSAPP_OPS_NUMBER }}",
"textBody": "={{ 'Urgent ' + $('Normalized Inbound').item.json.channel + ' message from ' + $('Normalized Inbound').item.json.from + ': ' + $json.output.summary }}"
},
"credentials": { "whatsAppApi": { "id": "REPLACE_ME", "name": "WhatsApp (support number)" } }
}
],
"connections": {
"Gmail Trigger": { "main": [ [ { "node": "Extract Email Fields", "type": "main", "index": 0 }, { "node": "List Attachments", "type": "main", "index": 0 } ] ] },
"Telegram Trigger": { "main": [ [ { "node": "Extract Telegram Fields", "type": "main", "index": 0 } ] ] },
"WhatsApp Trigger": { "main": [ [ { "node": "Extract WhatsApp Fields", "type": "main", "index": 0 } ] ] },
"Extract Email Fields": { "main": [ [ { "node": "Normalized Inbound", "type": "main", "index": 0 } ] ] },
"Extract Telegram Fields": { "main": [ [ { "node": "Normalized Inbound", "type": "main", "index": 0 } ] ] },
"Extract WhatsApp Fields": { "main": [ [ { "node": "Normalized Inbound", "type": "main", "index": 0 } ] ] },
"Normalized Inbound": { "main": [ [ { "node": "AI Agent - Triage & Draft", "type": "main", "index": 0 } ] ] },
"List Attachments": { "main": [ [ { "node": "Drive Configured?", "type": "main", "index": 0 } ] ] },
"Drive Configured?": { "main": [ [ { "node": "Loop Over Attachments", "type": "main", "index": 0 } ], [ { "node": "Attachments Done", "type": "main", "index": 0 } ] ] },
"Loop Over Attachments": {
"main": [
[ { "node": "Attachments Done", "type": "main", "index": 0 } ],
[ { "node": "Upload Attachment to Drive", "type": "main", "index": 0 } ]
]
},
"Upload Attachment to Drive": { "main": [ [ { "node": "Log Attachment to Sheet", "type": "main", "index": 0 } ] ] },
"Log Attachment to Sheet": { "main": [ [ { "node": "Loop Over Attachments", "type": "main", "index": 0 } ] ] },
"OpenAI Chat Model": { "ai_languageModel": [ [ { "node": "AI Agent - Triage & Draft", "type": "ai_languageModel", "index": 0 } ] ] },
"Google Gemini Chat Model": { "ai_languageModel": [ [ { "node": "AI Agent - Triage & Draft", "type": "ai_languageModel", "index": 0 } ] ] },
"Anthropic Chat Model": { "ai_languageModel": [ [ { "node": "AI Agent - Triage & Draft", "type": "ai_languageModel", "index": 0 } ] ] },
"Conversation Memory (per sender)": { "ai_memory": [ [ { "node": "AI Agent - Triage & Draft", "type": "ai_memory", "index": 0 } ] ] },
"Embeddings (OpenAI)": { "ai_embedding": [ [ { "node": "Company KB Search (RAG tool)", "type": "ai_embedding", "index": 0 } ] ] },
"Company KB Search (RAG tool)": { "ai_tool": [ [ { "node": "AI Agent - Triage & Draft", "type": "ai_tool", "index": 0 } ] ] },
"CRM Lookup (tool)": { "ai_tool": [ [ { "node": "AI Agent - Triage & Draft", "type": "ai_tool", "index": 0 } ] ] },
"Structured Output Parser": { "ai_outputParser": [ [ { "node": "AI Agent - Triage & Draft", "type": "ai_outputParser", "index": 0 } ] ] },
"AI Agent - Triage & Draft": { "main": [ [ { "node": "Route by Category/Priority", "type": "main", "index": 0 } ] ] },
"Route by Category/Priority": {
"main": [
[ { "node": "Log to Ops Sheet", "type": "main", "index": 0 }, { "node": "Create CRM Ticket (urgent)", "type": "main", "index": 0 }, { "node": "LINE Configured?", "type": "main", "index": 0 }, { "node": "Telegram Ops Configured?", "type": "main", "index": 0 }, { "node": "WhatsApp Ops Configured?", "type": "main", "index": 0 } ],
[ { "node": "Log to Ops Sheet", "type": "main", "index": 0 } ],
[ { "node": "Log to Ops Sheet", "type": "main", "index": 0 }, { "node": "Route Reply by Channel", "type": "main", "index": 0 } ]
]
},
"LINE Configured?": { "main": [ [ { "node": "Notify Ops Team (LINE)", "type": "main", "index": 0 } ], [] ] },
"Telegram Ops Configured?": { "main": [ [ { "node": "Notify Ops Team (Telegram)", "type": "main", "index": 0 } ], [] ] },
"WhatsApp Ops Configured?": { "main": [ [ { "node": "Notify Ops Team (WhatsApp)", "type": "main", "index": 0 } ], [] ] },
"Route Reply by Channel": {
"main": [
[ { "node": "Create Gmail Draft Reply", "type": "main", "index": 0 } ],
[ { "node": "Send Telegram Reply", "type": "main", "index": 0 } ],
[ { "node": "Send WhatsApp Reply", "type": "main", "index": 0 } ]
]
}
},
"active": false,
"settings": { "executionOrder": "v1" },
"pinData": {}
}