{
  "id": "lU8MeTqvPE0Eqxvw",
  "meta": {
    "instanceId": "c2d487d22eb340f8f43c55ff61f8c69909cb5c9301a99030a4a4ab5908a80ca6"
  },
  "name": "Automated B2B Lead Management and AI Outreach",
  "tags": [],
  "nodes": [
    {
      "id": "04d0678d-d5a0-4fd0-bcee-9ebd0a70d990",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -32,
        752
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "ce7c0fa0-ef44-408a-8c3a-e1aa6b7ec8fa",
      "name": "Load Test Leads",
      "type": "n8n-nodes-base.code",
      "position": [
        192,
        752
      ],
      "parameters": {
        "jsCode": "const leads = [{client_id: 'client_001', company_name: 'TechCorp Solutions', website: 'https://techcorp.example.com', contact_name: 'Sarah Johnson', contact_email: 'user@example.com', industry: 'SaaS', country: 'USA'}, {client_id: 'client_001', company_name: 'DataFlow Inc', website: 'https://dataflow.example.com', contact_name: 'Michael Chen', contact_email: 'user@example.com', industry: 'Data Analytics', country: 'Canada'}, {client_id: 'client_002', company_name: 'CloudScale Systems', website: 'https://cloudscale.example.com', contact_name: 'Emma Williams', contact_email: 'user@example.com', industry: 'Cloud Infrastructure', country: 'UK'}, {client_id: 'client_002', company_name: 'AI Innovations Ltd', website: 'https://aiinnovations.example.com', contact_name: 'David Martinez', contact_email: 'user@example.com', industry: 'Artificial Intelligence', country: 'Germany'}, {client_id: 'client_003', company_name: 'SecureNet Technologies', website: 'https://securenet.example.com', contact_name: 'Lisa Anderson', contact_email: 'user@example.com', industry: 'Cybersecurity', country: 'Australia'}]; return leads.map(lead => ({json: lead}));"
      },
      "typeVersion": 2
    },
    {
      "id": "ab087ddc-58fd-4bc0-b974-3f88e5721eb2",
      "name": "Enrich Lead via HTTP",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -16,
        1408
      ],
      "parameters": {
        "url": "https://jsonplaceholder.typicode.com/users/1",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "fe998826-49d3-4173-89a4-b220299d58a1",
      "name": "Check Enrichment Success",
      "type": "n8n-nodes-base.if",
      "position": [
        176,
        1408
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              },
              "leftValue": "={{ $json.id }}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "7ad98c76-2d01-4eb0-b24a-a4c77be9aaf0",
      "name": "Merge Enrichment Data",
      "type": "n8n-nodes-base.set",
      "position": [
        672,
        1264
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "enrichment_status",
              "type": "string",
              "value": "success"
            },
            {
              "id": "id-2",
              "name": "enriched",
              "type": "boolean",
              "value": true
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "7180fe74-2c6c-41b4-ab82-eaf246d162d3",
      "name": "Set Enrichment Failed Flag",
      "type": "n8n-nodes-base.set",
      "position": [
        432,
        1488
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "enrichment_status",
              "type": "string",
              "value": "failed"
            },
            {
              "id": "id-2",
              "name": "enriched",
              "type": "boolean",
              "value": false
            },
            {
              "id": "id-3",
              "name": "tech_stack",
              "type": "array",
              "value": "[]"
            },
            {
              "id": "id-4",
              "name": "employee_count",
              "type": "number",
              "value": 0
            },
            {
              "id": "id-5",
              "name": "estimated_revenue",
              "type": "number",
              "value": 0
            },
            {
              "id": "id-6",
              "name": "pain_points",
              "type": "string",
              "value": "Generic pain points - enrichment unavailable"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "4ff6a775-c1bb-4dee-bdc2-6f1aee9b6edc",
      "name": "Parse Enrichment Response",
      "type": "n8n-nodes-base.code",
      "position": [
        448,
        1264
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Get the original lead data from Load Test Leads node\nconst originalLead = $('Load Test Leads').item.json;\n\n// Get the enrichment response from the HTTP request\nconst enrichmentData = $input.item.json;\n\n// Extract and merge the data\nreturn {\n  ...originalLead,\n  enriched_name: enrichmentData.name || '',\n  enriched_username: enrichmentData.username || '',\n  enriched_email: enrichmentData.email || '',\n  enriched_phone: enrichmentData.phone || '',\n  enriched_website: enrichmentData.website || '',\n  enriched_company: enrichmentData.company?.name || '',\n  enriched_address: enrichmentData.address ? `${enrichmentData.address.street}, ${enrichmentData.address.city}` : '',\n  tech_stack: ['React', 'Node.js', 'PostgreSQL', 'AWS'],\n  employee_count: Math.floor(Math.random() * 500) + 50,\n  estimated_revenue: Math.floor(Math.random() * 10000000) + 1000000,\n  pain_points: `Scaling challenges in ${originalLead.industry}, need for automation and efficiency improvements`\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "c05662b5-d98f-4523-8835-1dd809b5a9d5",
      "name": "AI - Generate Outreach Email",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2272,
        2080
      ],
      "parameters": {
        "text": "=Generate a personalized cold outreach email for: Company: {{ $json.company_name }}, Industry: {{ $json.industry }}, Contact: {{ $json.contact_name }}, Pain Points: {{ $json.pain_points }}, Tech Stack: {{ $json.tech_stack.join(\", \") }}",
        "options": {
          "systemMessage": "You are an expert B2B sales copywriter specializing in cold outreach emails.\n\nYour task is to:\n1. Write a compelling subject line (under 50 characters)\n2. Write a personalized email body (under 150 words) that:\n   - References the company and industry\n   - Addresses their specific pain points\n   - Mentions their tech stack if relevant\n   - Includes a clear call-to-action\n   - Sounds natural and conversational, not salesy\n\nReturn the subject and body in the structured format."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "399939a2-022f-47b4-92e5-a456df1eaa84",
      "name": "OpenAI Chat Model - Email Gen",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2208,
        2288
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "bddc7898-5746-42fa-a37c-74e8f97b158a",
      "name": "Structured Output - Email",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        2368,
        2288
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"subject\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Email subject line\"\n\t\t},\n\t\t\"body\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Email body content\"\n\t\t}\n\t},\n\t\"required\": [\"subject\", \"body\"]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "a20c7674-68ef-4ccf-9c99-e80d4516e287",
      "name": "Extract Email Fields",
      "type": "n8n-nodes-base.code",
      "position": [
        2592,
        2080
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Extract email subject and body from AI output\nconst aiOutput = $json.output || {};\nconst emailSubject = aiOutput.subject || 'No subject generated';\nconst emailBody = aiOutput.body || 'No body generated';\n\n// Merge with existing lead data\nreturn {\n  ...item.json,\n  email_subject: emailSubject,\n  email_body: emailBody\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "643bc71b-e3fc-461b-9af9-f23aea8f0216",
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        6880,
        2240
      ],
      "webhookId": "a6fbcd53-b491-4776-ad78-4a50ee405e7d",
      "parameters": {
        "text": "={{ $json.email_body }}",
        "options": {},
        "subject": "={{ $json.email_subject }}",
        "toEmail": "={{ $json.contact_email }}",
        "fromEmail": "AI SDR Bot <user@example.com>",
        "emailFormat": "text"
      },
      "typeVersion": 2.1
    },
    {
      "id": "c6fad90c-05de-49c2-b72b-14df7e6a17e5",
      "name": "Prepare Email Event Log",
      "type": "n8n-nodes-base.set",
      "position": [
        7072,
        2240
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "event_type",
              "type": "string",
              "value": "email_sent"
            },
            {
              "id": "id-2",
              "name": "event_timestamp",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            },
            {
              "id": "id-3",
              "name": "payload_json",
              "type": "string",
              "value": "={{ JSON.stringify({subject: $json.email_subject, body: $json.email_body, to: $json.contact_email}) }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "4aace4a3-b6c9-4112-91a0-478b1b55d8be",
      "name": "Log Email Sent to DB",
      "type": "n8n-nodes-base.postgres",
      "position": [
        7280,
        2240
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $json.event_timestamp }}",
            "event_type": "={{ $json.event_type }}",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ $json.payload_json }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "4f093306-c04a-40ea-864b-9c381959dcbc",
      "name": "Simulate Reply Text",
      "type": "n8n-nodes-base.code",
      "position": [
        7760,
        2240
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Simulate different types of lead replies\nconst replies = [\n  // Interested replies\n  \"This looks interesting! Can we schedule a call next week to discuss further?\",\n  \"I'd love to learn more about this. What's the best time to chat?\",\n  \"We're actually looking for a solution like this. Can you send me more details?\",\n  \"Sounds promising. Let's set up a demo.\",\n  \n  // Not interested replies\n  \"Thanks, but we're not interested at this time.\",\n  \"We already have a solution in place. Please remove me from your list.\",\n  \"Not a fit for us right now.\",\n  \"Please unsubscribe me.\",\n  \n  // Follow up later replies\n  \"Interesting, but can you reach out again in Q3? We're tied up right now.\",\n  \"Not the right time, but maybe in a few months.\",\n  \"We're in the middle of a project. Can you follow up in 6 weeks?\",\n  \"Timing isn't great. Check back with me next quarter.\",\n  \n  // Unclear replies\n  \"Maybe. Send me some info.\",\n  \"I'll think about it.\",\n  \"Can you tell me more?\",\n  \"Hmm, not sure if this is relevant to us.\"\n];\n\n// Randomly select a reply\nconst randomReply = replies[Math.floor(Math.random() * replies.length)];\n\n// Return the item with the simulated reply added\nreturn {\n  json: {\n    ...($input.item.json),\n    reply_text: randomReply,\n    reply_received_at: new Date().toISOString()\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "6f2552ff-1f0e-4062-a264-39d9bed010f4",
      "name": "AI - Classify Reply Intent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        8016,
        2240
      ],
      "parameters": {
        "text": "=Classify this reply from {{ $json.contact_name }} at {{ $json.company_name }}: \"{{ $json.reply_text }}\"",
        "options": {
          "systemMessage": "You are an expert sales AI that classifies lead replies and suggests appropriate follow-up actions.\n\nYour task is to:\n1. Classify the intent as one of: interested, not_interested, follow_up_later, unclear\n2. Provide a confidence score (0-1)\n3. Suggest a brief follow-up message (under 100 words)\n\nClassification guidelines:\n- interested: Shows clear interest, asks questions, wants to learn more, requests a call/demo\n- not_interested: Explicitly declines, says not a fit, unsubscribes\n- follow_up_later: Asks to reconnect later, mentions timing issues, says \"maybe in the future\"\n- unclear: Vague response, needs clarification, ambiguous intent\n\nReturn the classification in the structured format."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "b76288f4-8a00-4d6b-a4a9-c462d5b1f28e",
      "name": "OpenAI Chat Model - Reply Classifier",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        7952,
        2480
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "8757e926-8f58-48bf-a443-60c2336b5963",
      "name": "Structured Output - Classification",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        8112,
        2480
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"intent\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [\"interested\", \"not_interested\", \"follow_up_later\", \"unclear\"],\n\t\t\t\"description\": \"Classification of reply intent\"\n\t\t},\n\t\t\"confidence\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"description\": \"Confidence score 0-1\"\n\t\t},\n\t\t\"suggested_reply\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Suggested next message to send\"\n\t\t}\n\t},\n\t\"required\": [\"intent\", \"confidence\", \"suggested_reply\"]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "5e421561-1120-413e-8e1b-feff6c355eeb",
      "name": "Route by Intent",
      "type": "n8n-nodes-base.switch",
      "position": [
        8448,
        2208
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "interested",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.output.intent }}",
                    "rightValue": "interested"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "follow_up_later",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.output.intent }}",
                    "rightValue": "follow_up_later"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "not_interested",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.output.intent }}",
                    "rightValue": "not_interested"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "unclear",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.output.intent }}",
                    "rightValue": "unclear"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "f263ceb7-c1cb-40da-a31a-0e346636f79f",
      "name": "Mark as Qualified",
      "type": "n8n-nodes-base.set",
      "position": [
        9120,
        1904
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "lead_status",
              "type": "string",
              "value": "qualified"
            },
            {
              "id": "id-2",
              "name": "qualification_date",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            },
            {
              "id": "id-3",
              "name": "ai_confidence",
              "type": "number",
              "value": "={{ $json.output.confidence }}"
            },
            {
              "id": "id-4",
              "name": "suggested_reply",
              "type": "string",
              "value": "={{ $json.output.suggested_reply }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "1c07b4ab-6f1c-467a-87a8-4fd3d21a2def",
      "name": "Log Qualified Event",
      "type": "n8n-nodes-base.postgres",
      "position": [
        10272,
        2048
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "qualified",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({status: 'qualified', confidence: $json.ai_confidence, reply: $json.reply_text}) }}"
          },
          "schema": [
            {
              "id": "client_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "client_id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "lead_email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "lead_email",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "event_type",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "event_type",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "payload_json",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "payload_json",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "created_at",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "created_at",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "client_id",
            "lead_email",
            "event_type",
            "payload_json",
            "created_at"
          ]
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "1db6decc-685b-4ab8-a553-7b3c2c7aff47",
      "name": "Calculate Follow-up Date",
      "type": "n8n-nodes-base.code",
      "position": [
        9120,
        2320
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Calculate follow-up date 7 days from now\nconst followUpDate = new Date();\nfollowUpDate.setDate(followUpDate.getDate() + 7);\n\nreturn {\n  json: {\n    ...item.json,\n    follow_up_date: followUpDate.toISOString()\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "963bb757-b701-4518-bb59-e78617e00d28",
      "name": "Prepare Follow-up Event",
      "type": "n8n-nodes-base.set",
      "position": [
        9936,
        2320
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "lead_status",
              "type": "string",
              "value": "follow_up_scheduled"
            },
            {
              "id": "id-2",
              "name": "scheduled_date",
              "type": "string",
              "value": "={{ $json.follow_up_date }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "c6e10226-b26d-42a7-b974-521190b6862b",
      "name": "Log Follow-up Event",
      "type": "n8n-nodes-base.postgres",
      "position": [
        10256,
        2320
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "follow_up_scheduled",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({follow_up_date: $json.follow_up_date, reply: $json.reply_text}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "9dacbdea-af90-43b8-802b-2377de7cd24f",
      "name": "Mark as Not Interested",
      "type": "n8n-nodes-base.set",
      "position": [
        9120,
        2496
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "lead_status",
              "type": "string",
              "value": "closed_lost"
            },
            {
              "id": "id-2",
              "name": "closed_date",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "2bae1599-4933-47e4-aa0c-9304625586b4",
      "name": "Log Closed Lost Event",
      "type": "n8n-nodes-base.postgres",
      "position": [
        9392,
        2496
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "closed_lost",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({reason: 'not_interested', reply: $json.reply_text}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "196d20b1-b571-41ac-b2a4-0e391f4fe4c4",
      "name": "Mark as Needs Review",
      "type": "n8n-nodes-base.set",
      "position": [
        9120,
        2672
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "lead_status",
              "type": "string",
              "value": "needs_manual_review"
            },
            {
              "id": "id-2",
              "name": "flagged_date",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "3e0eb401-0e65-4040-8471-037da7c01d26",
      "name": "Log Manual Review Event",
      "type": "n8n-nodes-base.postgres",
      "position": [
        9920,
        2672
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "needs_manual_review",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({reason: 'unclear_intent', reply: $json.reply_text}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "2ac0e1e6-ee42-477f-bcdd-46fc258dc95d",
      "name": "Aggregate All Results",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        10624,
        2080
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "c5b989f7-0f63-4609-92a4-80f6105dd461",
      "name": "Calculate Final Stats",
      "type": "n8n-nodes-base.code",
      "position": [
        11904,
        2336
      ],
      "parameters": {
        "jsCode": "// Calculate final statistics from all processed leads\nconst allData = $input.all();\n\nconst stats = {\n  total_leads: allData.length,\n  qualified: 0,\n  follow_up_scheduled: 0,\n  closed_lost: 0,\n  needs_manual_review: 0,\n  enrichment_success: 0,\n  enrichment_failed: 0,\n  avg_confidence: 0\n};\n\nlet totalConfidence = 0;\nlet confidenceCount = 0;\n\nfor (const item of allData) {\n  const data = item.json;\n  \n  // Count lead statuses\n  if (data.lead_status === 'qualified') {\n    stats.qualified++;\n  } else if (data.lead_status === 'follow_up_scheduled') {\n    stats.follow_up_scheduled++;\n  } else if (data.lead_status === 'closed_lost') {\n    stats.closed_lost++;\n  } else if (data.lead_status === 'needs_manual_review') {\n    stats.needs_manual_review++;\n  }\n  \n  // Count enrichment success/failure\n  if (data.enrichment_status === 'success') {\n    stats.enrichment_success++;\n  } else if (data.enrichment_status === 'failed') {\n    stats.enrichment_failed++;\n  }\n  \n  // Calculate average confidence\n  if (data.ai_confidence !== undefined && data.ai_confidence !== null) {\n    totalConfidence += data.ai_confidence;\n    confidenceCount++;\n  }\n}\n\n// Calculate average confidence\nif (confidenceCount > 0) {\n  stats.avg_confidence = (totalConfidence / confidenceCount).toFixed(2);\n}\n\n// Calculate percentages\nstats.qualified_rate = ((stats.qualified / stats.total_leads) * 100).toFixed(1) + '%';\nstats.enrichment_success_rate = ((stats.enrichment_success / stats.total_leads) * 100).toFixed(1) + '%';\n\nreturn [{ json: stats }];"
      },
      "typeVersion": 2
    },
    {
      "id": "979fa778-6ad4-4063-83af-14e010a721e5",
      "name": "Extra Enrichment API 2",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        656,
        1488
      ],
      "parameters": {
        "url": "=https://jsonplaceholder.typicode.com/posts/{{ Math.floor(Math.random() * 10) + 1 }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "97de1599-b0c9-4a1b-b1f5-fb3fc3085b06",
      "name": "Normalize Enrichment Data",
      "type": "n8n-nodes-base.code",
      "position": [
        1184,
        1280
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Get the original lead data from Load Test Leads node\nconst originalLead = $('Load Test Leads').item.json;\n\n// Get the first enrichment response from Enrich Lead via HTTP\nconst firstEnrichment = $('Enrich Lead via HTTP').item.json;\n\n// Get the second enrichment response from Extra Enrichment API 2\nconst secondEnrichment = $input.item.json;\n\n// Normalize and merge all enrichment data\nreturn {\n  ...originalLead,\n  // First enrichment data\n  enriched_name: firstEnrichment.name || '',\n  enriched_username: firstEnrichment.username || '',\n  enriched_email: firstEnrichment.email || '',\n  enriched_phone: firstEnrichment.phone || '',\n  enriched_website: firstEnrichment.website || '',\n  enriched_company: firstEnrichment.company?.name || '',\n  enriched_address: firstEnrichment.address ? `${firstEnrichment.address.street}, ${firstEnrichment.address.city}` : '',\n  \n  // Second enrichment data (additional fields)\n  extra_enriched_data: secondEnrichment.data || {},\n  extra_enriched_score: secondEnrichment.score || 0,\n  extra_enriched_tags: secondEnrichment.tags || [],\n  \n  // Combined tech stack and other fields\n  tech_stack: secondEnrichment.tech_stack || ['React', 'Node.js', 'PostgreSQL', 'AWS'],\n  employee_count: secondEnrichment.employee_count || Math.floor(Math.random() * 500) + 50,\n  estimated_revenue: secondEnrichment.estimated_revenue || Math.floor(Math.random() * 10000000) + 1000000,\n  pain_points: secondEnrichment.pain_points || `Scaling challenges in ${originalLead.industry}, need for automation and efficiency improvements`\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "3b8953fc-4f54-47ea-b34f-3e1edf50cd1c",
      "name": "Check Extra Enrichment Success",
      "type": "n8n-nodes-base.if",
      "position": [
        896,
        1488
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              },
              "leftValue": "={{ $json.id }}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "2e49688f-d11f-4c40-bbc5-eed790e830f3",
      "name": "Log Enrichment Success",
      "type": "n8n-nodes-base.set",
      "position": [
        1424,
        1280
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "extra_enrichment_status",
              "type": "string",
              "value": "success"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "8698436d-f5da-4d5b-8cb5-0e923a77a05e",
      "name": "Insert Enrichment Success Event",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1680,
        1280
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "enrichment_success",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({extra_data: true}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "1e384c69-c4fd-4287-9747-5fc815fb4cc1",
      "name": "Log Enrichment Failure",
      "type": "n8n-nodes-base.set",
      "position": [
        1184,
        1504
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "extra_enrichment_status",
              "type": "string",
              "value": "failed"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "6544838f-3b0e-499b-b215-09e60c4c62dd",
      "name": "Insert Enrichment Failed Event",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1424,
        1504
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "enrichment_failed",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({reason: 'extra_api_failed'}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "df3aa0db-5a61-4c44-937b-9d1647675467",
      "name": "Compute Lead Score",
      "type": "n8n-nodes-base.code",
      "position": [
        992,
        2080
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Calculate lead score based on multiple factors\nconst item = $input.item.json;\n\nlet score = 0;\n\n// Industry scoring (0-30 points)\nconst highValueIndustries = ['SaaS', 'Cloud Infrastructure', 'Artificial Intelligence', 'Cybersecurity', 'Data Analytics'];\nconst mediumValueIndustries = ['FinTech', 'E-commerce', 'Healthcare Tech', 'EdTech'];\n\nif (highValueIndustries.includes(item.industry)) {\n  score += 30;\n} else if (mediumValueIndustries.includes(item.industry)) {\n  score += 20;\n} else {\n  score += 10;\n}\n\n// Country scoring (0-20 points)\nconst tier1Countries = ['USA', 'UK', 'Germany', 'Canada', 'Australia'];\nconst tier2Countries = ['France', 'Netherlands', 'Sweden', 'Singapore', 'Japan'];\n\nif (tier1Countries.includes(item.country)) {\n  score += 20;\n} else if (tier2Countries.includes(item.country)) {\n  score += 15;\n} else {\n  score += 10;\n}\n\n// Employee count scoring (0-25 points)\nconst employeeCount = item.employee_count || 0;\nif (employeeCount >= 200) {\n  score += 25;\n} else if (employeeCount >= 100) {\n  score += 20;\n} else if (employeeCount >= 50) {\n  score += 15;\n} else {\n  score += 10;\n}\n\n// Estimated revenue scoring (0-25 points)\nconst revenue = item.estimated_revenue || 0;\nif (revenue >= 5000000) {\n  score += 25;\n} else if (revenue >= 2000000) {\n  score += 20;\n} else if (revenue >= 1000000) {\n  score += 15;\n} else {\n  score += 10;\n}\n\n// Pain points detail scoring (0-10 points)\nconst painPointsLength = (item.pain_points || '').length;\nif (painPointsLength > 100) {\n  score += 10;\n} else if (painPointsLength > 50) {\n  score += 7;\n} else {\n  score += 5;\n}\n\n// Enrichment success bonus (0-10 points)\nif (item.enrichment_status === 'success') {\n  score += 10;\n}\n\n// Determine score tier\nlet scoreTier = 'LOW';\nif (score >= 80) {\n  scoreTier = 'HIGH';\n} else if (score >= 60) {\n  scoreTier = 'MEDIUM';\n}\n\nreturn {\n  ...item,\n  lead_score: score,\n  score_tier: scoreTier\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "3700fef3-2fbf-4072-9a3a-9ec616ed543d",
      "name": "Branch by Lead Score",
      "type": "n8n-nodes-base.switch",
      "position": [
        1216,
        2064
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "HIGH",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "number",
                      "operation": "gte"
                    },
                    "leftValue": "={{ $json.lead_score }}",
                    "rightValue": 70
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "MEDIUM",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "number",
                      "operation": "gte"
                    },
                    "leftValue": "={{ $json.lead_score }}",
                    "rightValue": 40
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "LOW",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "number",
                      "operation": "lt"
                    },
                    "leftValue": "={{ $json.lead_score }}",
                    "rightValue": 40
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "2cd99946-6af3-4877-b192-04579ca323e3",
      "name": "Set HIGH Score Attributes",
      "type": "n8n-nodes-base.set",
      "position": [
        1504,
        1872
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "score_tier",
              "type": "string",
              "value": "HIGH"
            },
            {
              "id": "id-2",
              "name": "outreach_tone",
              "type": "string",
              "value": "premium"
            },
            {
              "id": "id-3",
              "name": "priority_flag",
              "type": "boolean",
              "value": true
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "dbf73d0d-82bf-4e38-8b4b-545170439df9",
      "name": "Log HIGH Score Event",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1680,
        1872
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "lead_scored_high",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({score: $json.lead_score, tier: 'HIGH'}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "3bccd5ca-85d9-487f-8967-fae75f413309",
      "name": "Set MEDIUM Score Attributes",
      "type": "n8n-nodes-base.set",
      "position": [
        1504,
        2080
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "score_tier",
              "type": "string",
              "value": "MEDIUM"
            },
            {
              "id": "id-2",
              "name": "outreach_tone",
              "type": "string",
              "value": "standard"
            },
            {
              "id": "id-3",
              "name": "priority_flag",
              "type": "boolean",
              "value": false
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "a5eb6b54-5104-4f75-9086-a302f9a64cde",
      "name": "Log MEDIUM Score Event",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1680,
        2080
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "lead_scored_medium",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({score: $json.lead_score, tier: 'MEDIUM'}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "9e870315-d671-4157-baef-76fffb6756c1",
      "name": "Set LOW Score Attributes",
      "type": "n8n-nodes-base.set",
      "position": [
        1504,
        2288
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "score_tier",
              "type": "string",
              "value": "LOW"
            },
            {
              "id": "id-2",
              "name": "outreach_tone",
              "type": "string",
              "value": "basic"
            },
            {
              "id": "id-3",
              "name": "priority_flag",
              "type": "boolean",
              "value": false
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "f379f08d-5980-479e-b90e-bc9a4edf7745",
      "name": "Log LOW Score Event",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1680,
        2288
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "lead_scored_low",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({score: $json.lead_score, tier: 'LOW'}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "26a901ad-2990-4f61-b708-48264cd88273",
      "name": "Generate LinkedIn Message",
      "type": "n8n-nodes-base.code",
      "position": [
        3728,
        2096
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Generate a short LinkedIn DM message based on the email body\nconst emailBody = $json.email_body || '';\nconst contactName = $json.contact_name || 'there';\nconst companyName = $json.company_name || '';\n\n// Create a shorter, more casual version for LinkedIn\n// Extract key points from email and make it conversational\nconst linkedInMessage = `Hi ${contactName},\\n\\nI sent you an email about how we can help ${companyName}, but thought I'd reach out here too.\\n\\nWould love to connect and chat about the challenges you're facing in ${$json.industry || 'your industry'}.\\n\\nBest,\\nAI SDR Bot`;\n\nreturn {\n  json: {\n    ...item.json,\n    linkedin_message: linkedInMessage\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "5c7826e0-e548-438d-b4d4-541a4c3ebccf",
      "name": "Generate WhatsApp Message",
      "type": "n8n-nodes-base.code",
      "position": [
        3904,
        2096
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Generate a short WhatsApp/SMS message based on the email body\nconst emailBody = $json.email_body || '';\nconst contactName = $json.contact_name || 'there';\nconst companyName = $json.company_name || '';\n\n// Extract first sentence or key point from email body\nlet shortMessage = emailBody.split('.')[0] + '.';\n\n// If too long, create a custom short message\nif (shortMessage.length > 160) {\n  shortMessage = `Hi ${contactName.split(' ')[0]}, I noticed ${companyName} might benefit from our solution. Quick chat? Reply YES for details.`;\n}\n\n// Ensure it's under SMS character limit (160 chars)\nif (shortMessage.length > 160) {\n  shortMessage = shortMessage.substring(0, 157) + '...';\n}\n\nreturn {\n  ...item.json,\n  whatsapp_message: shortMessage,\n  message_length: shortMessage.length\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "08476904-e459-41c1-b1d3-e2ca015c6ba8",
      "name": "Check if Multichannel Eligible",
      "type": "n8n-nodes-base.if",
      "position": [
        4096,
        2096
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.score_tier }}",
              "rightValue": "HIGH"
            },
            {
              "id": "id-2",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.score_tier }}",
              "rightValue": "MEDIUM"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "5ede2ca6-7cf6-49a1-a463-8db3bca380db",
      "name": "Simulate LinkedIn Send",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4336,
        2000
      ],
      "parameters": {
        "url": "https://jsonplaceholder.typicode.com/posts",
        "method": "POST",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "message",
              "value": "={{ $json.linkedin_message }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "fc42a215-a14e-410d-9a5a-77a557ec8a8f",
      "name": "Check LinkedIn Send Success",
      "type": "n8n-nodes-base.if",
      "position": [
        5136,
        2016
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              },
              "leftValue": "={{ $json.id }}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "4b4b7f5c-5f57-4889-a99b-819d369fa223",
      "name": "Log LinkedIn Success",
      "type": "n8n-nodes-base.postgres",
      "position": [
        5568,
        1936
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "linkedin_sent",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({message: $json.linkedin_message}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "8f7ea44d-a3ac-49af-8ebe-533eb26067cc",
      "name": "Log LinkedIn Failure",
      "type": "n8n-nodes-base.postgres",
      "position": [
        5344,
        2032
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "linkedin_failed",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({reason: 'api_error'}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "e86411ae-e356-41df-bbe3-7d7af600f490",
      "name": "Simulate WhatsApp Send",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        5792,
        2032
      ],
      "parameters": {
        "url": "https://jsonplaceholder.typicode.com/posts",
        "method": "POST",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "message",
              "value": "={{ $json.whatsapp_message }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "a2000b43-df14-485f-abf1-77ccd43162e2",
      "name": "Check WhatsApp Send Success",
      "type": "n8n-nodes-base.if",
      "position": [
        6656,
        2016
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              },
              "leftValue": "={{ $json.id }}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "b736ae57-1090-4969-950c-c7b99c506d5a",
      "name": "Log WhatsApp Success",
      "type": "n8n-nodes-base.postgres",
      "position": [
        6896,
        1920
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "whatsapp_sent",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({message: $json.whatsapp_message}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "f84aa8fd-0a55-42c5-b24d-f8f8036936f2",
      "name": "Log WhatsApp Failure",
      "type": "n8n-nodes-base.postgres",
      "position": [
        7056,
        2032
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "whatsapp_failed",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({reason: 'api_error'}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "547495e0-56dd-4012-a247-20d75a879a09",
      "name": "Create Subject Variants A/B",
      "type": "n8n-nodes-base.code",
      "position": [
        2768,
        2080
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Create A/B test variants for email subject line\nconst originalSubject = $json.email_subject || 'No subject';\n\n// Create two variants\nconst subject_A = originalSubject;\nconst subject_B = originalSubject.replace(/^/, '🎯 '); // Add emoji prefix for variant B\n\n// Randomly choose which variant to use\nconst chosen_variant = Math.random() < 0.5 ? 'A' : 'B';\nconst final_subject = chosen_variant === 'A' ? subject_A : subject_B;\n\nreturn {\n  ...item.json,\n  subject_A: subject_A,\n  subject_B: subject_B,\n  chosen_variant: chosen_variant,\n  email_subject: final_subject\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "5c4c1413-c371-4143-a41a-aa46de1d5f04",
      "name": "Log Subject Variant",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2944,
        2080
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "subject_variant",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({variant: $json.chosen_variant, subject_A: $json.subject_A, subject_B: $json.subject_B}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "3835a177-c174-4c30-aa1a-92fe40f61715",
      "name": "AI - Draft Meeting Follow-up",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        9296,
        1904
      ],
      "parameters": {
        "text": "=Draft a meeting follow-up for {{ $json.contact_name }} at {{ $json.company_name }} who showed interest",
        "options": {
          "systemMessage": "You are a sales assistant. Draft a brief meeting follow-up message proposing a 30-minute call. Suggest a time 2 days from now at 2pm. Return meeting_message, suggested_time, and duration_minutes."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "b13e9b63-677a-45f2-a37c-3ceb421dbbf2",
      "name": "OpenAI Chat Model - Meeting",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        9248,
        2096
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "51bc0d26-5f33-4426-8469-060cc74a543d",
      "name": "Structured Output - Meeting",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        9408,
        2096
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"meeting_message\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Meeting follow-up message\"\n\t\t},\n\t\t\"suggested_time\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Suggested meeting time\"\n\t\t},\n\t\t\"duration_minutes\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"description\": \"Meeting duration in minutes\"\n\t\t}\n\t},\n\t\"required\": [\"meeting_message\", \"suggested_time\", \"duration_minutes\"]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "d1636f71-c508-419f-9190-acf72672d541",
      "name": "Create Meeting Object",
      "type": "n8n-nodes-base.code",
      "position": [
        9680,
        1904
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Create meeting object from AI-generated meeting follow-up\nconst aiOutput = $json.output || {};\n\n// Extract meeting details from AI output\nconst meetingObject = {\n  client_id: $json.client_id,\n  lead_email: $json.contact_email,\n  status: 'scheduled',\n  suggested_time: aiOutput.suggested_time || new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString(),\n  metadata_json: JSON.stringify({\n    company_name: $json.company_name,\n    contact_name: $json.contact_name,\n    industry: $json.industry,\n    ai_confidence: $json.ai_confidence,\n    meeting_notes: aiOutput.meeting_notes || '',\n    agenda: aiOutput.agenda || ''\n  })\n};\n\nreturn {\n  json: {\n    ...$json,\n    ...meetingObject\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "e9316ad2-9b86-4a4f-b209-cef168bad7fd",
      "name": "Insert Meeting Record",
      "type": "n8n-nodes-base.postgres",
      "position": [
        10048,
        2048
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "meetings"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "status": "proposed",
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "lead_email": "={{ $json.contact_email }}",
            "metadata_json": "={{ $json.metadata_json }}",
            "suggested_time": "={{ $json.suggested_time }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "731f2d70-ce53-4d0e-a2a9-19dc01d503f6",
      "name": "Calculate Extended Follow-up Date",
      "type": "n8n-nodes-base.code",
      "position": [
        9376,
        2320
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Calculate follow-up date 14 days from now\nconst followUpDate = new Date();\nfollowUpDate.setDate(followUpDate.getDate() + 14);\n\nreturn {\n  json: {\n    ...item.json,\n    follow_up_date: followUpDate.toISOString()\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "0798406a-1c6a-4e6a-88a2-1e825806a4f4",
      "name": "Insert Extended Follow-up Event",
      "type": "n8n-nodes-base.postgres",
      "position": [
        9680,
        2320
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "extended_follow_up_scheduled",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({follow_up_date: $json.extended_follow_up_date, days: 14}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "1a018f04-1670-4182-ae1e-5cd6258c5c3e",
      "name": "Send Slack Notification",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        9408,
        2672
      ],
      "parameters": {
        "url": "https://hooks.slack.com/services/DUMMY/WEBHOOK",
        "method": "POST",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "jsonBody": "={\n  \"text\": \"Manual review needed for {{ $json.contact_name }}\"\n}",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.3
    },
    {
      "id": "e650c2bc-8dc2-4f7c-a6ee-63fcd31cd449",
      "name": "Log Manual Review Notification",
      "type": "n8n-nodes-base.postgres",
      "position": [
        9664,
        2672
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "slack_notification_sent",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({reason: 'manual_review'}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "4fbecab6-a64a-4fb0-830e-cdf4c0155857",
      "name": "Aggregate by Lead Score",
      "type": "n8n-nodes-base.code",
      "position": [
        11120,
        2080
      ],
      "parameters": {
        "jsCode": "// Aggregate counts by lead score tier (HIGH/MEDIUM/LOW)\nconst allData = $input.all();\n\nconst scoreAggregation = {\n  HIGH: 0,\n  MEDIUM: 0,\n  LOW: 0,\n  UNKNOWN: 0\n};\n\nfor (const item of allData) {\n  const data = item.json;\n  const leadScore = data.score_tier || 'UNKNOWN';\n  \n  if (scoreAggregation.hasOwnProperty(leadScore)) {\n    scoreAggregation[leadScore]++;\n  } else {\n    scoreAggregation.UNKNOWN++;\n  }\n}\n\nreturn [{ json: scoreAggregation }];"
      },
      "typeVersion": 2
    },
    {
      "id": "5ceb9b79-83bf-489f-91b6-5e6dddb77457",
      "name": "Aggregate by Channel",
      "type": "n8n-nodes-base.code",
      "position": [
        11376,
        2080
      ],
      "parameters": {
        "jsCode": "// Aggregate counts by channel used (email_only vs multichannel)\nconst allData = $input.all();\n\nconst channelStats = {\n  email_only: 0,\n  multichannel: 0,\n  linkedin_sent: 0,\n  whatsapp_sent: 0,\n  total_touchpoints: 0\n};\n\nfor (const item of allData) {\n  const data = item.json;\n  \n  // Check if multichannel was used (LinkedIn or WhatsApp)\n  const hasLinkedIn = data.linkedin_sent === true || data.linkedin_status === 'success';\n  const hasWhatsApp = data.whatsapp_sent === true || data.whatsapp_status === 'success';\n  \n  if (hasLinkedIn || hasWhatsApp) {\n    channelStats.multichannel++;\n    channelStats.total_touchpoints++; // Email\n    \n    if (hasLinkedIn) {\n      channelStats.linkedin_sent++;\n      channelStats.total_touchpoints++;\n    }\n    \n    if (hasWhatsApp) {\n      channelStats.whatsapp_sent++;\n      channelStats.total_touchpoints++;\n    }\n  } else {\n    channelStats.email_only++;\n    channelStats.total_touchpoints++;\n  }\n}\n\n// Calculate percentages\nconst totalLeads = channelStats.email_only + channelStats.multichannel;\nif (totalLeads > 0) {\n  channelStats.multichannel_rate = ((channelStats.multichannel / totalLeads) * 100).toFixed(1) + '%';\n  channelStats.avg_touchpoints_per_lead = (channelStats.total_touchpoints / totalLeads).toFixed(2);\n}\n\nreturn [{ json: channelStats }];"
      },
      "typeVersion": 2
    },
    {
      "id": "212f746b-3f73-4ac9-93ab-e80355bc871d",
      "name": "Prepare Analytics Daily Row",
      "type": "n8n-nodes-base.code",
      "position": [
        11648,
        2080
      ],
      "parameters": {
        "jsCode": "// Prepare analytics_daily row with aggregated metrics\nconst allData = $input.all();\n\n// Initialize counters\nconst analytics = {\n  date: new Date().toISOString().split('T')[0], // YYYY-MM-DD format\n  total_leads: allData.length,\n  high_score: 0,\n  medium_score: 0,\n  low_score: 0,\n  meetings_created: 0,\n  multichannel_count: 0\n};\n\n// Count metrics from all items\nfor (const item of allData) {\n  const data = item.json;\n  \n  // Count by lead score\n  if (data.score_tier === 'HIGH') {\n    analytics.high_score++;\n  } else if (data.score_tier === 'MEDIUM') {\n    analytics.medium_score++;\n  } else if (data.score_tier === 'LOW') {\n    analytics.low_score++;\n  }\n  \n  // Count meetings created\n  if (data.meeting_scheduled === true || data.lead_status === 'qualified') {\n    analytics.meetings_created++;\n  }\n  \n  // Count multichannel outreach\n  if (data.linkedin_sent === true || data.whatsapp_sent === true) {\n    analytics.multichannel_count++;\n  }\n}\n\nreturn [{ json: analytics }];"
      },
      "typeVersion": 2
    },
    {
      "id": "9c12b7c9-b4c5-4cb9-9247-7a63272bf3eb",
      "name": "Insert Analytics Daily Row",
      "type": "n8n-nodes-base.postgres",
      "position": [
        11120,
        2336
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "analytics_daily"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "date": "={{ $now.format('yyyy-MM-dd') }}",
            "low_score": "={{ $json.low_score }}",
            "created_at": "={{ $now.toISO() }}",
            "high_score": "={{ $json.high_score }}",
            "total_leads": "={{ $json.total_leads }}",
            "medium_score": "={{ $json.medium_score }}",
            "meetings_created": "={{ $json.meetings_created }}",
            "multichannel_count": "={{ $json.multichannel_count }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "36637bfd-f264-4db9-8dbc-55f170e214da",
      "name": "Enrich Final Stats",
      "type": "n8n-nodes-base.code",
      "position": [
        11680,
        2336
      ],
      "parameters": {
        "jsCode": "// Enrich final stats with new metrics from analytics aggregation\nconst allData = $input.all();\n\n// Get the base stats from Calculate Final Stats node\nconst baseStats = allData[0]?.json || {};\n\n// Calculate additional enrichment metrics\nlet totalEnrichmentAttempts = 0;\nlet successfulEnrichments = 0;\nlet failedEnrichments = 0;\nlet avgEnrichmentScore = 0;\nlet enrichmentScoreCount = 0;\n\n// Calculate channel distribution\nconst channelStats = {\n  email_only: 0,\n  email_linkedin: 0,\n  email_whatsapp: 0,\n  multichannel: 0\n};\n\n// Calculate lead score distribution\nconst scoreDistribution = {\n  high: 0,\n  medium: 0,\n  low: 0\n};\n\nfor (const item of allData) {\n  const data = item.json;\n  \n  // Count enrichment metrics\n  if (data.enrichment_status) {\n    totalEnrichmentAttempts++;\n    if (data.enrichment_status === 'success') {\n      successfulEnrichments++;\n    } else if (data.enrichment_status === 'failed') {\n      failedEnrichments++;\n    }\n  }\n  \n  // Calculate enrichment scores if available\n  if (data.enrichment_score !== undefined && data.enrichment_score !== null) {\n    avgEnrichmentScore += data.enrichment_score;\n    enrichmentScoreCount++;\n  }\n  \n  // Count channel usage\n  if (data.linkedin_sent && data.whatsapp_sent) {\n    channelStats.multichannel++;\n  } else if (data.linkedin_sent) {\n    channelStats.email_linkedin++;\n  } else if (data.whatsapp_sent) {\n    channelStats.email_whatsapp++;\n  } else {\n    channelStats.email_only++;\n  }\n  \n  // Count lead score distribution\n  if (data.score_tier === 'high') {\n    scoreDistribution.high++;\n  } else if (data.score_tier === 'medium') {\n    scoreDistribution.medium++;\n  } else if (data.score_tier === 'low') {\n    scoreDistribution.low++;\n  }\n}\n\n// Calculate averages\nif (enrichmentScoreCount > 0) {\n  avgEnrichmentScore = (avgEnrichmentScore / enrichmentScoreCount).toFixed(2);\n}\n\n// Merge with base stats\nconst enrichedStats = {\n  ...baseStats,\n  enrichment_metrics: {\n    total_attempts: totalEnrichmentAttempts,\n    successful: successfulEnrichments,\n    failed: failedEnrichments,\n    success_rate: totalEnrichmentAttempts > 0 ? ((successfulEnrichments / totalEnrichmentAttempts) * 100).toFixed(1) + '%' : '0%',\n    avg_enrichment_score: avgEnrichmentScore\n  },\n  channel_distribution: channelStats,\n  lead_score_distribution: scoreDistribution,\n  multichannel_rate: baseStats.total_leads > 0 ? ((channelStats.multichannel / baseStats.total_leads) * 100).toFixed(1) + '%' : '0%',\n  high_score_rate: baseStats.total_leads > 0 ? ((scoreDistribution.high / baseStats.total_leads) * 100).toFixed(1) + '%' : '0%'\n};\n\nreturn [{ json: enrichedStats }];"
      },
      "typeVersion": 2
    },
    {
      "id": "8bd2cd97-2411-421c-9486-1a855a8a6620",
      "name": "Validate Email Format",
      "type": "n8n-nodes-base.code",
      "position": [
        416,
        752
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const email = $json.contact_email || '';\nconst emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\nconst isValid = emailRegex.test(email);\nconst domain = email.includes('@') ? email.split('@')[1] : '';\n\nreturn {\n  ...item.json,\n  invalid_email: !isValid,\n  email_domain: domain\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "7249f15b-a036-4ded-b518-e373214a845e",
      "name": "Check Suppression List",
      "type": "n8n-nodes-base.code",
      "position": [
        640,
        752
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const blockedDomains = ['spam.com', 'blocked.net', 'noreply.org'];\nconst blockedEmails = ['test@example.com', 'user@example.com'];\n\nconst email = $json.contact_email || '';\nconst domain = $json.email_domain || '';\n\nconst isBlocked = blockedDomains.includes(domain) || blockedEmails.includes(email);\n\nreturn {\n  ...item.json,\n  blocked_domain: blockedDomains.includes(domain),\n  blocked_email: blockedEmails.includes(email),\n  is_suppressed: isBlocked\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "d8df6962-2015-441b-b039-785c225a59b5",
      "name": "Check if Invalid or Suppressed",
      "type": "n8n-nodes-base.if",
      "position": [
        864,
        752
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.invalid_email }}",
              "rightValue": true
            },
            {
              "id": "id-2",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.is_suppressed }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "9ca556a9-dbd3-46d3-a36d-ba4a94b945d6",
      "name": "Log Invalid Lead Event",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1136,
        736
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "suppressed",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({invalid_email: $json.invalid_email, is_suppressed: $json.is_suppressed, reason: $json.invalid_email ? 'invalid_email' : 'suppressed'}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "162bbc08-9e96-49dc-a741-ec468c42484b",
      "name": "Load Config",
      "type": "n8n-nodes-base.code",
      "position": [
        1664,
        1504
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const config = {\n  email_limit: 100,\n  linkedin_limit: 50,\n  whatsapp_limit: 30,\n  quiet_hours: false,\n  quiet_start: 22,\n  quiet_end: 8\n};\n\nconst currentHour = new Date().getHours();\nconst isQuietHours = currentHour >= config.quiet_start || currentHour < config.quiet_end;\n\nreturn {\n  ...item.json,\n  config: config,\n  is_quiet_hours: isQuietHours\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "cf547e84-dc89-4ab0-9076-d0c69c29ae58",
      "name": "Check Email Rate Limit",
      "type": "n8n-nodes-base.code",
      "position": [
        3120,
        2080
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const config = $json.config || {};\nconst emailLimit = config.email_limit || 100;\nconst isQuietHours = $json.is_quiet_hours || false;\nconst currentCount = Math.floor(Math.random() * 120);\n\nconst withinLimit = currentCount < emailLimit && !isQuietHours;\n\nreturn {\n  ...item.json,\n  email_rate_ok: withinLimit,\n  email_current_count: currentCount\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "3f449110-8f36-4a94-9b17-899e4f56e292",
      "name": "Email Rate OK?",
      "type": "n8n-nodes-base.if",
      "position": [
        3296,
        2080
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.email_rate_ok }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "5819bf89-2ae8-440d-9941-7f1eb6640c5f",
      "name": "Log Email Rate Limited",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3504,
        2000
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "rate_limited_email",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({current_count: $json.email_current_count, is_quiet_hours: $json.is_quiet_hours}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "9658c74e-8d04-4be7-afcc-8c065de85681",
      "name": "Check LinkedIn Rate Limit",
      "type": "n8n-nodes-base.code",
      "position": [
        4544,
        2000
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const config = $json.config || {};\nconst linkedinLimit = config.linkedin_limit || 50;\nconst currentCount = Math.floor(Math.random() * 60);\n\nconst withinLimit = currentCount < linkedinLimit;\n\nreturn {\n  ...item.json,\n  linkedin_rate_ok: withinLimit,\n  linkedin_current_count: currentCount\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "c2517e5f-308e-4c36-9b5b-969b06c5cfb8",
      "name": "LinkedIn Rate OK?",
      "type": "n8n-nodes-base.if",
      "position": [
        4736,
        2000
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.linkedin_rate_ok }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "249cf3ce-d80b-43d5-8a32-1c52a8a0e21c",
      "name": "Log LinkedIn Rate Limited",
      "type": "n8n-nodes-base.postgres",
      "position": [
        4944,
        1904
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "rate_limited_linkedin",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({current_count: $json.linkedin_current_count}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "79c38f58-73d2-4b3f-89b4-d09856538862",
      "name": "Check WhatsApp Rate Limit",
      "type": "n8n-nodes-base.code",
      "position": [
        6032,
        1936
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const config = $json.config || {};\nconst whatsappLimit = config.whatsapp_limit || 30;\nconst currentCount = Math.floor(Math.random() * 40);\n\nconst withinLimit = currentCount < whatsappLimit;\nconst gdprSensitive = $json.gdpr_sensitive || false;\nconst allowWhatsApp = withinLimit && !gdprSensitive;\n\nreturn {\n  ...item.json,\n  whatsapp_rate_ok: allowWhatsApp,\n  whatsapp_current_count: currentCount\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "230a8685-c5ea-4bb4-b33c-2eb67f76aefa",
      "name": "WhatsApp Rate OK?",
      "type": "n8n-nodes-base.if",
      "position": [
        6240,
        1936
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.whatsapp_rate_ok }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "56b2a16e-f8d7-42d3-aa70-bc2e8d97b18d",
      "name": "Log WhatsApp Rate Limited",
      "type": "n8n-nodes-base.postgres",
      "position": [
        6480,
        1856
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "rate_limited_whatsapp",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({current_count: $json.whatsapp_current_count, gdpr_blocked: $json.gdpr_sensitive}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "1c17b9d8-c224-4114-90c8-c0cf2ab1c0b4",
      "name": "Set Geo Compliance Flags",
      "type": "n8n-nodes-base.code",
      "position": [
        1856,
        1504
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const country = $json.country || '';\nconst gdprCountries = ['UK', 'Germany', 'France', 'Italy', 'Spain', 'Netherlands', 'Belgium', 'Austria', 'Sweden', 'Denmark', 'Finland', 'Ireland', 'Poland'];\nconst blockedCountries = ['North Korea', 'Iran', 'Syria'];\n\nconst gdprSensitive = gdprCountries.includes(country);\nconst doNotContact = blockedCountries.includes(country);\n\nreturn {\n  ...item.json,\n  gdpr_sensitive: gdprSensitive,\n  do_not_contact: doNotContact\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "fadbe2eb-c1a0-44ae-b5e2-d297259acfe5",
      "name": "Check Do Not Contact",
      "type": "n8n-nodes-base.if",
      "position": [
        -16,
        2064
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.do_not_contact }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "fb009c16-0f6e-41f4-8423-b89460c69a5c",
      "name": "Log Geo Blocked",
      "type": "n8n-nodes-base.postgres",
      "position": [
        10208,
        1472
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "geo_blocked",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({country: $json.country, reason: 'do_not_contact'}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "db865351-7d9c-4fea-867c-02a4f84b3d7a",
      "name": "Check GDPR Sensitive",
      "type": "n8n-nodes-base.if",
      "position": [
        176,
        2064
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.gdpr_sensitive }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "2e49a3fa-528f-4d7c-87d1-e861c065e256",
      "name": "Log GDPR Sensitive",
      "type": "n8n-nodes-base.postgres",
      "position": [
        400,
        1984
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "gdpr_sensitive",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({country: $json.country, gdpr_sensitive: true}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "ca12bbb5-874d-4f59-9ca0-492633f04af9",
      "name": "Check if Needs Human Review",
      "type": "n8n-nodes-base.if",
      "position": [
        9120,
        1600
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.output.intent }}",
              "rightValue": "interested"
            },
            {
              "id": "id-2",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.output.confidence }}",
              "rightValue": "0.8"
            },
            {
              "id": "id-3",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.output.intent }}",
              "rightValue": "unclear"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "9997cb54-3bef-4b37-88bf-47c4002cb914",
      "name": "Send Human Review Alert",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        9520,
        1584
      ],
      "parameters": {
        "url": "https://hooks.slack.com/services/DUMMY/HUMAN_REVIEW",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"text\": \"🚨 Human review needed\",\n  \"lead\": $json.contact_name,\n  \"company\": $json.company_name,\n  \"email\": $json.contact_email,\n  \"intent\": $json.output.intent,\n  \"confidence\": $json.output.confidence,\n  \"reply\": $json.reply_text\n}",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.3
    },
    {
      "id": "ca5f3230-9b44-4b44-bd29-0170167b512e",
      "name": "Log Escalated to Human",
      "type": "n8n-nodes-base.postgres",
      "position": [
        9760,
        1584
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "escalated_to_human",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({intent: $json.output.intent, confidence: $json.output.confidence, reply: $json.reply_text}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "7e26afa0-e9ad-4f7d-85ef-9afd0f23e559",
      "name": "Calculate Best Send Time",
      "type": "n8n-nodes-base.code",
      "position": [
        608,
        2080
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const country = $json.country || 'USA';\nconst timezoneMap = {\n  'USA': 'America/New_York',\n  'UK': 'Europe/London',\n  'Germany': 'Europe/Berlin',\n  'Canada': 'America/Toronto',\n  'Australia': 'Australia/Sydney'\n};\n\nconst timezone = timezoneMap[country] || 'UTC';\nconst tomorrow = new Date();\ntomorrow.setDate(tomorrow.getDate() + 1);\ntomorrow.setHours(10, 0, 0, 0);\n\nreturn {\n  ...item.json,\n  timezone: timezone,\n  best_send_time: tomorrow.toISOString()\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "789113d4-2b97-4ff1-9443-2e1219e171c3",
      "name": "Log Send Time Planned",
      "type": "n8n-nodes-base.postgres",
      "position": [
        800,
        2080
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "lead_events"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "client_id": "={{ $json.client_id }}",
            "created_at": "={{ $now.toISO() }}",
            "event_type": "send_time_planned",
            "lead_email": "={{ $json.contact_email }}",
            "payload_json": "={{ JSON.stringify({best_send_time: $json.best_send_time, timezone: $json.timezone}) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "5e97956a-9895-473d-97f8-f4509b50e224",
      "name": "Estimate Lead Cost",
      "type": "n8n-nodes-base.code",
      "position": [
        11392,
        2432
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const emailCost = 0.01;\nconst linkedinCost = 0.05;\nconst whatsappCost = 0.03;\nconst aiCallCost = 0.10;\n\nlet totalCost = 0;\nlet aiCalls = 0;\n\nif ($json.email_sent || $json.event_type === 'email_sent') {\n  totalCost += emailCost;\n}\nif ($json.linkedin_sent || $json.event_type === 'linkedin_sent') {\n  totalCost += linkedinCost;\n}\nif ($json.whatsapp_sent || $json.event_type === 'whatsapp_sent') {\n  totalCost += whatsappCost;\n}\n\naiCalls = 2;\ntotalCost += aiCalls * aiCallCost;\n\nreturn {\n  ...item.json,\n  lead_cost: parseFloat(totalCost.toFixed(2)),\n  ai_calls: aiCalls\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "2b70c4b5-b293-415b-932b-de1c5a7531e4",
      "name": "Build Execution Metadata",
      "type": "n8n-nodes-base.code",
      "position": [
        11664,
        2592
      ],
      "parameters": {
        "jsCode": "// Generate execution metadata from final stats\nconst stats = $input.first().json;\n\n// Generate a random UUID for run_id\nconst generateUUID = () => {\n  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {\n    const r = Math.random() * 16 | 0;\n    const v = c === 'x' ? r : (r & 0x3 | 0x8);\n    return v.toString(16);\n  });\n};\n\nconst executionMetadata = {\n  run_id: generateUUID(),\n  timestamp: new Date().toISOString(),\n  total_leads: stats.total_leads || 0,\n  qualified_leads: stats.qualified || 0,\n  meetings_created: stats.qualified || 0,\n  total_cost: stats.total_cost || 0\n};\n\nreturn {\n  json: {\n    ...stats,\n    execution_metadata: executionMetadata\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "47145c9f-a54c-4614-afaa-1e32b372e856",
      "name": "Insert Execution Run Record",
      "type": "n8n-nodes-base.postgres",
      "position": [
        11904,
        2592
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "execution_runs"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "run_id": "={{ $json.execution_metadata.run_id }}",
            "created_at": "={{ $now.toISO() }}",
            "summary_json": "={{ JSON.stringify($json) }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "9142c60a-b181-4595-8855-b7e33646e364",
      "name": "AI - Generate Human Summary",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        11152,
        2880
      ],
      "parameters": {
        "text": "=Summarize this workflow run: Total leads: {{ $json.total_leads }}, Qualified: {{ $json.qualified }}, Meetings: {{ $json.meetings_created }}, Cost: {{ $json.total_cost }}",
        "options": {
          "systemMessage": "You are a workflow analyst. Create a concise 2-3 sentence human-readable summary of this workflow execution. Highlight key metrics and any notable insights or patterns. Return only the summary text in the summary field."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "4ca74924-e98f-4a44-bc90-9b6a3a72d8e6",
      "name": "OpenAI Chat Model - Summary",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        11056,
        3088
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "600e633a-9210-41df-9358-1b86da7bc850",
      "name": "Structured Output - Summary",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        11360,
        3088
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"summary\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Human-readable summary of the workflow execution\"\n\t\t}\n\t},\n\t\"required\": [\"summary\"]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "9c37a1df-3c3c-4b46-9f40-a5f323666093",
      "name": "Merge Summary with Stats",
      "type": "n8n-nodes-base.code",
      "position": [
        11552,
        2880
      ],
      "parameters": {
        "jsCode": "// Merge AI-generated summary with final stats\nconst aiSummary = $json.output || {};\nconst stats = $json;\n\n// Create final summary object\nconst finalSummary = {\n  ...stats,\n  ai_summary: aiSummary.summary || '',\n  key_insights: aiSummary.key_insights || [],\n  recommendations: aiSummary.recommendations || [],\n  final_summary: `Workflow completed successfully. ${aiSummary.summary || 'No summary available.'}`\n};\n\nreturn [{ json: finalSummary }];"
      },
      "typeVersion": 2
    },
    {
      "id": "1d94b817-6cfd-4d9e-984e-58b3c954d018",
      "name": "Prepare Final Output",
      "type": "n8n-nodes-base.code",
      "position": [
        11792,
        2880
      ],
      "parameters": {
        "jsCode": "// Prepare final clean output with stats, summary, and run metadata\nconst inputData = $input.all();\nconst firstItem = inputData[0]?.json || {};\n\n// Extract stats from the enriched stats\nconst stats = {\n  total_leads: firstItem.total_leads || 0,\n  qualified: firstItem.qualified || 0,\n  follow_up_scheduled: firstItem.follow_up_scheduled || 0,\n  closed_lost: firstItem.closed_lost || 0,\n  needs_manual_review: firstItem.needs_manual_review || 0,\n  enrichment_success: firstItem.enrichment_success || 0,\n  enrichment_failed: firstItem.enrichment_failed || 0,\n  avg_confidence: firstItem.avg_confidence || 0,\n  qualified_rate: firstItem.qualified_rate || '0%',\n  enrichment_success_rate: firstItem.enrichment_success_rate || '0%',\n  multichannel_rate: firstItem.multichannel_rate || '0%',\n  high_score_rate: firstItem.high_score_rate || '0%'\n};\n\n// Extract summary if available\nconst final_summary = firstItem.summary || firstItem.ai_summary || 'Workflow execution completed successfully';\n\n// Generate run ID\nconst run_id = $execution.id || `run_${Date.now()}`;\nconst run_timestamp = new Date().toISOString();\n\n// Build final output\nconst finalOutput = {\n  run_id: run_id,\n  run_timestamp: run_timestamp,\n  stats: stats,\n  final_summary: final_summary,\n  execution_status: 'completed'\n};\n\nreturn [{ json: finalOutput }];"
      },
      "typeVersion": 2
    },
    {
      "id": "9649936c-2ea0-4ce0-9485-0b2d5e6b3723",
      "name": "Notify Team – Run Summary",
      "type": "n8n-nodes-base.slack",
      "position": [
        11648,
        3200
      ],
      "webhookId": "44fb004a-65b5-44e2-80cb-8b1a1d652ba7",
      "parameters": {
        "text": "=📊 *SDR Workflow Run Complete*\n\n*Run ID:* {{ $json.run_id }}\n*Timestamp:* {{ $json.run_timestamp }}\n\n*Results:*\n• Total Leads: {{ $json.stats.total_leads }}\n• Qualified: {{ $json.stats.qualified }}\n• Follow-ups: {{ $json.stats.follow_up_scheduled }}\n• Closed Lost: {{ $json.stats.closed_lost }}\n• Manual Review: {{ $json.stats.needs_manual_review }}\n\n*Rates:*\n• Qualification Rate: {{ $json.stats.qualified_rate }}\n• Enrichment Success: {{ $json.stats.enrichment_success_rate }}\n• Multichannel: {{ $json.stats.multichannel_rate }}\n\n*Summary:* {{ $json.final_summary }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#sdr-runs"
        },
        "otherOptions": {}
      },
      "typeVersion": 2.4
    },
    {
      "id": "0c222e82-8e99-4a4e-ae87-2d953413b6eb",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1344,
        1392
      ],
      "parameters": {
        "width": 1168,
        "height": 384,
        "content": "## How it works\nThis workflow takes raw B2B leads, validates and enriches them, then uses AI to send personalized cold emails and classify replies.\n\n1. Leads come in (test data, CSV, Sheet, or webhook). Emails are validated and checked against a suppression list so bad or blocked contacts are filtered out.\n2. Valid leads are enriched via HTTP APIs (company, role, website, etc.). Failed enrichments are flagged and skipped for outreach.\n3. For enriched leads, an AI node generates a short personalized outreach email, which is sent via your email provider. All send events are logged.\n4. When replies come back (or in test mode, from a simulator), another AI node classifies intent (interested / follow-up / not a fit / unclear) and routes the lead accordingly.\n5. At the end, stats are calculated and a summary is sent to Slack.\n\n## Setup steps\n1. Connect credentials: email service, enrichment API(s), database, and Slack.\n2. Review suppression rules and lead fields (country, industry, etc.).\n3. Edit the AI prompts (email copy + reply classification) to match your offer and tone.\n4. Set your real entry node (Sheet/webhook/CSV) and disable the test lead generator.\n5. Run once with a small test list, check logs and Slack summary, then go live."
      },
      "typeVersion": 1
    },
    {
      "id": "f821a604-3b8d-47b4-bad8-5e537ae996d6",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -64,
        624
      ],
      "parameters": {
        "color": 7,
        "width": 1344,
        "height": 320,
        "content": "## Input & Lead Validation\n\nReceives leads from test data, CSV, Sheets, or webhooks, validates email format, and checks the suppression list. Only clean, eligible leads continue, while rejected leads are logged."
      },
      "typeVersion": 1
    },
    {
      "id": "67e1b5de-76fc-4324-b2e3-b77ecbfbf3f2",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -64,
        1136
      ],
      "parameters": {
        "color": 7,
        "width": 2064,
        "height": 528,
        "content": "## Lead Enrichment\n\nCalls one or more external enrichment APIs to add company, website, role and other details. Normalizes responses, flags leads where enrichment failed, and logs both success and failure."
      },
      "typeVersion": 1
    },
    {
      "id": "37376a8a-a799-4436-954f-2e0dfbf32689",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -64,
        1808
      ],
      "parameters": {
        "color": 7,
        "width": 2064,
        "height": 640,
        "content": "## Lead Scoring & Segmentation\n\nComputes a lead score using industry, country, company size and other signals. Splits leads into HIGH / MEDIUM / LOW segments and logs scoring events for analytics."
      },
      "typeVersion": 1
    },
    {
      "id": "32bf7b58-41f6-4b64-afcd-b0eac940ecc9",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2112,
        1808
      ],
      "parameters": {
        "color": 7,
        "width": 5328,
        "height": 640,
        "content": "## AI Email Generation & Send\n\nUses AI to generate personalized cold emails, creates subject line A/B variants, sends the emails, and logs every send event to the database."
      },
      "typeVersion": 1
    },
    {
      "id": "4e1e4ed6-fed2-4370-864f-46313200046e",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7600,
        2080
      ],
      "parameters": {
        "color": 7,
        "width": 1088,
        "height": 544,
        "content": "## Replies & AI Classification\n\nSimulates or ingests replies from leads, uses AI to classify intent (interested, follow-up, not interested, unclear), and routes each lead to the appropriate branch."
      },
      "typeVersion": 1
    },
    {
      "id": "8469f085-d4ac-4c61-b3af-5264482c2fbc",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        8928,
        1328
      ],
      "parameters": {
        "color": 7,
        "width": 1840,
        "height": 1552,
        "content": "## Status & Follow-up\n\nUpdates lead status (qualified, follow-up, not interested, needs review), generates AI-powered follow-ups and meeting info, calculates follow-up dates, and sends alerts when human review is needed."
      },
      "typeVersion": 1
    },
    {
      "id": "9a78c7fe-f87d-4fe7-aee9-c53661a048bf",
      "name": "Sticky Note14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        10880,
        1888
      ],
      "parameters": {
        "color": 7,
        "width": 1392,
        "height": 1488,
        "content": "## Analytics & Reporting\n\nAggregates results by score, channel, and status, calculates final metrics and cost estimates, stores daily analytics rows, and uses AI to generate a human-readable summary sent to the team (e.g. via Slack)."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d573cd76-8911-4e83-b412-3cb3c6c40369",
  "connections": {
    "Send Email": {
      "main": [
        [
          {
            "node": "Prepare Email Event Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load Config": {
      "main": [
        [
          {
            "node": "Set Geo Compliance Flags",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Rate OK?": {
      "main": [
        [
          {
            "node": "Log Email Rate Limited",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate LinkedIn Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Load Test Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load Test Leads": {
      "main": [
        [
          {
            "node": "Validate Email Format",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Geo Blocked": {
      "main": [
        [
          {
            "node": "Aggregate All Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Intent": {
      "main": [
        [
          {
            "node": "Mark as Qualified",
            "type": "main",
            "index": 0
          },
          {
            "node": "Check if Needs Human Review",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Calculate Follow-up Date",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Mark as Not Interested",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Mark as Needs Review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LinkedIn Rate OK?": {
      "main": [
        [
          {
            "node": "Log LinkedIn Rate Limited",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check LinkedIn Send Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark as Qualified": {
      "main": [
        [
          {
            "node": "AI - Draft Meeting Follow-up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp Rate OK?": {
      "main": [
        [
          {
            "node": "Log WhatsApp Rate Limited",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check WhatsApp Send Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compute Lead Score": {
      "main": [
        [
          {
            "node": "Branch by Lead Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enrich Final Stats": {
      "main": [
        [
          {
            "node": "Calculate Final Stats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Estimate Lead Cost": {
      "main": [
        [
          {
            "node": "Enrich Final Stats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log GDPR Sensitive": {
      "main": [
        [
          {
            "node": "Calculate Best Send Time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Follow-up Event": {
      "main": [
        [
          {
            "node": "Aggregate All Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log LOW Score Event": {
      "main": [
        [
          {
            "node": "AI - Generate Outreach Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Qualified Event": {
      "main": [
        [
          {
            "node": "Aggregate All Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Subject Variant": {
      "main": [
        [
          {
            "node": "Check Email Rate Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simulate Reply Text": {
      "main": [
        [
          {
            "node": "AI - Classify Reply Intent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate by Channel": {
      "main": [
        [
          {
            "node": "Prepare Analytics Daily Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Branch by Lead Score": {
      "main": [
        [
          {
            "node": "Set HIGH Score Attributes",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set MEDIUM Score Attributes",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set LOW Score Attributes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Do Not Contact": {
      "main": [
        [
          {
            "node": "Log Geo Blocked",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check GDPR Sensitive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check GDPR Sensitive": {
      "main": [
        [
          {
            "node": "Log GDPR Sensitive",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Calculate Best Send Time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enrich Lead via HTTP": {
      "main": [
        [
          {
            "node": "Check Enrichment Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Email Fields": {
      "main": [
        [
          {
            "node": "Create Subject Variants A/B",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Email Sent to DB": {
      "main": [
        [
          {
            "node": "Simulate Reply Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log HIGH Score Event": {
      "main": [
        [
          {
            "node": "AI - Generate Outreach Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log LinkedIn Failure": {
      "main": [
        [
          {
            "node": "Simulate WhatsApp Send",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log LinkedIn Success": {
      "main": [
        [
          {
            "node": "Simulate WhatsApp Send",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log WhatsApp Failure": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log WhatsApp Success": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark as Needs Review": {
      "main": [
        [
          {
            "node": "Send Slack Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Final Output": {
      "main": [
        [
          {
            "node": "Notify Team – Run Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate All Results": {
      "main": [
        [
          {
            "node": "Aggregate by Lead Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Final Stats": {
      "main": [
        [
          {
            "node": "Build Execution Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Meeting Object": {
      "main": [
        [
          {
            "node": "Insert Meeting Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Meeting Record": {
      "main": [
        [
          {
            "node": "Log Qualified Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Closed Lost Event": {
      "main": [
        [
          {
            "node": "Aggregate All Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Send Time Planned": {
      "main": [
        [
          {
            "node": "Compute Lead Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Enrichment Data": {
      "main": [
        [
          {
            "node": "Extra Enrichment API 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Email Format": {
      "main": [
        [
          {
            "node": "Check Suppression List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Email Rate Limit": {
      "main": [
        [
          {
            "node": "Email Rate OK?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Suppression List": {
      "main": [
        [
          {
            "node": "Check if Invalid or Suppressed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extra Enrichment API 2": {
      "main": [
        [
          {
            "node": "Check Extra Enrichment Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Email Rate Limited": {
      "main": [
        [
          {
            "node": "Generate LinkedIn Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Enrichment Failure": {
      "main": [
        [
          {
            "node": "Insert Enrichment Failed Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Enrichment Success": {
      "main": [
        [
          {
            "node": "Insert Enrichment Success Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Escalated to Human": {
      "main": [
        [
          {
            "node": "Mark as Qualified",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Invalid Lead Event": {
      "main": [
        [
          {
            "node": "Aggregate All Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log MEDIUM Score Event": {
      "main": [
        [
          {
            "node": "AI - Generate Outreach Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark as Not Interested": {
      "main": [
        [
          {
            "node": "Log Closed Lost Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simulate LinkedIn Send": {
      "main": [
        [
          {
            "node": "Check LinkedIn Rate Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simulate WhatsApp Send": {
      "main": [
        [
          {
            "node": "Check WhatsApp Send Success",
            "type": "main",
            "index": 0
          },
          {
            "node": "Check WhatsApp Rate Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate by Lead Score": {
      "main": [
        [
          {
            "node": "Aggregate by Channel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Manual Review Event": {
      "main": [
        [
          {
            "node": "Aggregate All Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Email Event Log": {
      "main": [
        [
          {
            "node": "Log Email Sent to DB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Follow-up Event": {
      "main": [
        [
          {
            "node": "Log Follow-up Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Human Review Alert": {
      "main": [
        [
          {
            "node": "Log Escalated to Human",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Slack Notification": {
      "main": [
        [
          {
            "node": "Log Manual Review Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Execution Metadata": {
      "main": [
        [
          {
            "node": "Insert Execution Run Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Best Send Time": {
      "main": [
        [
          {
            "node": "Log Send Time Planned",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Follow-up Date": {
      "main": [
        [
          {
            "node": "Calculate Extended Follow-up Date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Enrichment Success": {
      "main": [
        [
          {
            "node": "Parse Enrichment Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Enrichment Failed Flag",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Summary with Stats": {
      "main": [
        [
          {
            "node": "Prepare Final Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Geo Compliance Flags": {
      "main": [
        [
          {
            "node": "Check Do Not Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set LOW Score Attributes": {
      "main": [
        [
          {
            "node": "Log LOW Score Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check LinkedIn Rate Limit": {
      "main": [
        [
          {
            "node": "LinkedIn Rate OK?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check WhatsApp Rate Limit": {
      "main": [
        [
          {
            "node": "WhatsApp Rate OK?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate LinkedIn Message": {
      "main": [
        [
          {
            "node": "Generate WhatsApp Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate WhatsApp Message": {
      "main": [
        [
          {
            "node": "Check if Multichannel Eligible",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log LinkedIn Rate Limited": {
      "main": [
        [
          {
            "node": "Check LinkedIn Send Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log WhatsApp Rate Limited": {
      "main": [
        [
          {
            "node": "Check WhatsApp Send Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Enrichment Data": {
      "main": [
        [
          {
            "node": "Log Enrichment Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Enrichment Response": {
      "main": [
        [
          {
            "node": "Merge Enrichment Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set HIGH Score Attributes": {
      "main": [
        [
          {
            "node": "Log HIGH Score Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output - Email": {
      "ai_outputParser": [
        [
          {
            "node": "AI - Generate Outreach Email",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "AI - Classify Reply Intent": {
      "main": [
        [
          {
            "node": "Route by Intent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Analytics Daily Row": {
      "main": [
        [
          {
            "node": "Enrich Final Stats",
            "type": "main",
            "index": 0
          },
          {
            "node": "Estimate Lead Cost",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Enrichment Failed Flag": {
      "main": [
        [
          {
            "node": "Extra Enrichment API 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI - Generate Human Summary": {
      "main": [
        [
          {
            "node": "Merge Summary with Stats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check LinkedIn Send Success": {
      "main": [
        [
          {
            "node": "Log LinkedIn Success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log LinkedIn Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check WhatsApp Send Success": {
      "main": [
        [
          {
            "node": "Log WhatsApp Success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log WhatsApp Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Needs Human Review": {
      "main": [
        [
          {
            "node": "Send Human Review Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Mark as Qualified",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Subject Variants A/B": {
      "main": [
        [
          {
            "node": "Log Subject Variant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Execution Run Record": {
      "main": [
        [
          {
            "node": "AI - Generate Human Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model - Meeting": {
      "ai_languageModel": [
        [
          {
            "node": "AI - Draft Meeting Follow-up",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model - Summary": {
      "ai_languageModel": [
        [
          {
            "node": "AI - Generate Human Summary",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Analytics Daily Row": {
      "main": [
        [
          {
            "node": "Insert Analytics Daily Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set MEDIUM Score Attributes": {
      "main": [
        [
          {
            "node": "Log MEDIUM Score Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output - Meeting": {
      "ai_outputParser": [
        [
          {
            "node": "AI - Draft Meeting Follow-up",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output - Summary": {
      "ai_outputParser": [
        [
          {
            "node": "AI - Generate Human Summary",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "AI - Draft Meeting Follow-up": {
      "main": [
        [
          {
            "node": "Create Meeting Object",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI - Generate Outreach Email": {
      "main": [
        [
          {
            "node": "Extract Email Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model - Email Gen": {
      "ai_languageModel": [
        [
          {
            "node": "AI - Generate Outreach Email",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Check Extra Enrichment Success": {
      "main": [
        [
          {
            "node": "Normalize Enrichment Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Enrichment Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Invalid or Suppressed": {
      "main": [
        [
          {
            "node": "Log Invalid Lead Event",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Enrich Lead via HTTP",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Multichannel Eligible": {
      "main": [
        [
          {
            "node": "Simulate LinkedIn Send",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Enrichment Failed Event": {
      "main": [
        [
          {
            "node": "Load Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Manual Review Notification": {
      "main": [
        [
          {
            "node": "Log Manual Review Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Enrichment Success Event": {
      "main": [
        [
          {
            "node": "Load Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Extended Follow-up Event": {
      "main": [
        [
          {
            "node": "Prepare Follow-up Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Extended Follow-up Date": {
      "main": [
        [
          {
            "node": "Insert Extended Follow-up Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output - Classification": {
      "ai_outputParser": [
        [
          {
            "node": "AI - Classify Reply Intent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model - Reply Classifier": {
      "ai_languageModel": [
        [
          {
            "node": "AI - Classify Reply Intent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}