{
  "active": false,
  "connections": {
    "Get Leads": {
      "main": [
        [
          {
            "index": 0,
            "node": "Read Leads Sheet",
            "type": "main"
          }
        ]
      ]
    },
    "Normalize Leads": {
      "main": [
        [
          {
            "index": 0,
            "node": "Summarize Company (LLM)",
            "type": "main"
          }
        ]
      ]
    },
    "Read Leads Sheet": {
      "main": [
        [
          {
            "index": 0,
            "node": "Normalize Leads",
            "type": "main"
          }
        ]
      ]
    },
    "Split in Batches": {
      "main": [
        [],
        [
          {
            "index": 0,
            "node": "Log Enriched Leads",
            "type": "main"
          }
        ]
      ]
    },
    "Summarize Company (LLM)": {
      "main": [
        [
          {
            "index": 0,
            "node": "Write Icebreaker",
            "type": "main"
          }
        ]
      ]
    },
    "Write Icebreaker": {
      "main": [
        [
          {
            "index": 0,
            "node": "Split in Batches",
            "type": "main"
          }
        ]
      ]
    },
    "Log Enriched Leads": {
      "main": [
        [
          {
            "index": 0,
            "node": "Split in Batches",
            "type": "main"
          }
        ]
      ]
    }
  },
  "id": "wf-03-lead-enrichment",
  "meta": {
    "instanceId": "n8n-template-factory",
    "templateCredsSetupCompleted": false
  },
  "name": "Lead Enrichment Cold Outreach",
  "nodes": [
    {
      "id": "node-trigger",
      "name": "Get Leads",
      "parameters": {},
      "position": [
        0,
        0
      ],
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1
    },
    {
      "id": "node-read-sheet",
      "name": "Read Leads Sheet",
      "parameters": {
        "method": "GET",
        "url": "={{ ($env.MOCK_API_URL || 'https://sheets.googleapis.com') + '/v4/spreadsheets/' + 'YOUR_SPREADSHEET_ID' + '/values/Leads!A1:F50' }}"
      },
      "position": [
        240,
        0
      ],
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2
    },
    {
      "id": "node-normalize",
      "name": "Normalize Leads",
      "parameters": {
        "jsCode": "const data = $input.first().json;\nconst rows = (data.values || []).slice(1);\nconst seen = new Set();\nconst out = [];\n// Cot sheet Leads theo contact.csv (suite/schemas/contact.schema.json):\n// [name, source, email, phone, company, tags]\nfor (const row of rows) {\n  const name = String(row[0] || '').trim();\n  const source = String(row[1] || 'sheet').trim();\n  const email = String(row[2] || '').trim().toLowerCase();\n  if (!email || !email.includes('@')) continue;\n  if (seen.has(email)) continue;\n  seen.add(email);\n  const phone = String(row[3] || '').trim();\n  const company = String(row[4] || '').trim();\n  const tags = String(row[5] || '').trim();\n  const domain = email.split('@')[1].replace(/^www\\./, '');\n  out.push({ json: { name, source, email, phone, company, tags, domain } });\n}\nif (out.length === 0) throw new Error('No valid leads found in sheet');\nreturn out;",
        "mode": "runOnceForAllItems"
      },
      "position": [
        480,
        0
      ],
      "type": "n8n-nodes-base.code",
      "typeVersion": 2
    },
    {
      "id": "node-summarize",
      "name": "Summarize Company (LLM)",
      "parameters": {
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_OPENAI_API_KEY"
            }
          ]
        },
        "jsonBody": "={{ JSON.stringify({ model: 'gpt-4o-mini', response_format: { type: 'json_object' }, messages: [{ role: 'user', content: 'Summarize this company in one sentence for a cold outreach email. Company: ' + $json.company + ' (' + $json.domain + '). Tags: ' + $json.tags }] }) }}",
        "method": "POST",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "url": "={{ ($env.MOCK_API_URL || 'https://api.openai.com') + '/v1/chat/completions' }}"
      },
      "position": [
        720,
        0
      ],
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2
    },
    {
      "id": "node-icebreaker",
      "name": "Write Icebreaker",
      "parameters": {
        "jsCode": "const leads = $('Normalize Leads').all().map((i) => i.json);\nconst summaries = $input.all().map((i) => i.json);\nreturn summaries.map((s, idx) => {\n  const content = s.choices && s.choices[0] ? s.choices[0].message.content : '{}';\n  let parsed = {};\n  try { parsed = JSON.parse(content); } catch (e) { parsed = {}; }\n  const lead = leads[idx] || leads[0] || {};\n  const summary = parsed.summary || '';\n  const who = lead.name || lead.email || 'there';\n  const about = lead.company ? 'loved what ' + lead.company + ' is doing' : 'came across your profile';\n  const tagNote = lead.tags ? ' (' + lead.tags + ')' : '';\n  return { json: { ...lead, summary, icebreaker: 'Hi ' + who + ', ' + about + ' — ' + summary + tagNote + ' Would love to show you how we can help.' } };\n});",
        "mode": "runOnceForAllItems"
      },
      "position": [
        960,
        0
      ],
      "type": "n8n-nodes-base.code",
      "typeVersion": 2
    },
    {
      "id": "node-split",
      "name": "Split in Batches",
      "parameters": {
        "batchSize": 10,
        "options": {}
      },
      "position": [
        1200,
        0
      ],
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3
    },
    {
      "id": "node-log",
      "name": "Log Enriched Leads",
      "parameters": {
        "jsonBody": "={{ JSON.stringify({ range: 'Enriched!A1', values: $input.all().map((i) => [i.json.name, i.json.email, i.json.phone, i.json.company, i.json.domain, i.json.summary, i.json.icebreaker]) }) }}",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "url": "={{ ($env.MOCK_API_URL || 'https://sheets.googleapis.com') + '/v4/spreadsheets/' + 'YOUR_SPREADSHEET_ID' + '/values/Enriched!A1:append' }}"
      },
      "position": [
        1440,
        0
      ],
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2
    }
  ],
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null
}