{
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "name": "LeadFusion - AI Lead Enrichment Workflow",
  "tags": [],
  "nodes": [
    {
      "id": "61b4b6d1-48c9-485a-be3a-86ce40129b82",
      "name": "\ud83d\udce9 Mailchimp Subscriber Trigger",
      "type": "n8n-nodes-base.mailchimpTrigger",
      "position": [
        -416,
        272
      ],
      "parameters": {
        "list": "YOUR_MAILCHIMP_LIST_ID",
        "events": [
          "subscribe"
        ],
        "sources": [
          "admin"
        ]
      },
      "credentials": {
        "mailchimpApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "02f90776-c4f6-498d-9b59-a3adf441aec0",
      "name": "\ud83d\udcca Extract Subscriber Data",
      "type": "n8n-nodes-base.code",
      "position": [
        -192,
        272
      ],
      "parameters": {
        "jsCode": "// n8n Code node (JavaScript)\nconst output = [];\n\nfor (const item of items) {\n  const data = item.json;\n\n  const firstName = data[\"data[merges][FNAME]\"] || \"\";\n  const lastName = data[\"data[merges][LNAME]\"] || \"\";\n\n  output.push({\n    email: data[\"data[email]\"] || \"\",\n    firstName,\n    lastName,\n    fullName: `${firstName} ${lastName}`.trim(),\n    tags: [],\n    listId: data[\"data[list_id]\"] || \"\",\n    subscribedAt: new Date(data[\"fired_at\"]).toISOString()\n  });\n}\n\nreturn output.map(o => ({ json: o }));"
      },
      "typeVersion": 2
    },
    {
      "id": "b5a3ce32-5793-442e-bbe3-4c6fd44c6779",
      "name": "\ud83e\udd16 Lead Enrichment AI",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        32,
        272
      ],
      "parameters": {
        "text": "=You are an expert lead enrichment AI. Based on the provided email and name, enrich the lead with likely professional information and provide a lead score.  \n\nInput:  \nEmail: {{ $json.email }}  \nName: {{ $json.fullName }}  \n\nOutput:  \nRespond only in valid JSON format with the following keys:  \n- company  \n- jobTitle  \n- industry  \n- linkedinUrl  \n- intent  \n- leadScore (1-100, based on email domain and name quality)  \n- confidence (1-100, accuracy of enrichment guess)",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "85488739-d25a-4b83-8116-0c42f8638869",
      "name": "\ud83e\udde0 OpenAI Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        96,
        496
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "91ef7930-18a9-4fe8-855c-8f486d527934",
      "name": "\ud83d\udd0e Parse & Merge Enrichment",
      "type": "n8n-nodes-base.code",
      "position": [
        384,
        272
      ],
      "parameters": {
        "jsCode": "// Parse OpenAI response and merge with original subscriber data\nconst item = $input.first();\n\n// Fallback: take current input if node not found\nlet subscriberData = {};\ntry {\n  subscriberData = $node['Extract Subscriber Data']?.json || item.json;\n} catch (e) {\n  subscriberData = item.json;\n}\n\nlet enrichedData = {\n  company: 'Unknown Company',\n  jobTitle: 'Unknown Role',\n  industry: 'Unknown Industry',\n  linkedinUrl: '',\n  intent: 'General interest',\n  leadScore: 50,\n  confidence: 30\n};\n\n// Try to parse OpenAI response (already JSON)\ntry {\n  const openaiResponse = item.json;\n  let content = openaiResponse.output || openaiResponse;\n\n  if (typeof content === 'string') {\n    content = content.replace(/```json|```/g, '').trim();\n    content = JSON.parse(content);\n  }\n\n  enrichedData = { ...enrichedData, ...content };\n} catch (error) {\n  // Parsing failed \u2013 keep defaults\n}\n\nconst finalData = {\n  ...subscriberData,\n  ...enrichedData,\n  enrichedAt: new Date().toISOString()\n};\n\nreturn { json: finalData };"
      },
      "typeVersion": 2
    },
    {
      "id": "c9240bca-e758-4e90-8c89-39a57a50fa8b",
      "name": "\ud83d\udc8e High-Value Lead Check",
      "type": "n8n-nodes-base.if",
      "position": [
        608,
        80
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "condition-1",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.leadScore }}",
              "rightValue": 70
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "3374813d-ee35-4f65-9ac7-c2c257897996",
      "name": "\ud83d\udcca HubSpot Contact Sync",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        608,
        416
      ],
      "parameters": {
        "email": "={{ $('\ud83d\udcca Extract Subscriber Data').item.json.email }}",
        "options": {},
        "authentication": "appToken",
        "additionalFields": {
          "industry": "={{ $json.industry }}",
          "jobTitle": "={{ $json.jobTitle }}",
          "lastName": "={{ $('\ud83d\udcca Extract Subscriber Data').item.json.lastName }}",
          "firstName": "={{ $('\ud83d\udcca Extract Subscriber Data').item.json.firstName }}",
          "companyName": "={{ $json.company }}"
        }
      },
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2,
      "continueOnFail": true
    },
    {
      "id": "8c30c26c-1374-446e-979c-e99d1b41a10a",
      "name": "\ud83d\udc64 Pipedrive Person Create",
      "type": "n8n-nodes-base.pipedrive",
      "position": [
        608,
        608
      ],
      "parameters": {
        "name": "={{ $('\ud83d\udcca Extract Subscriber Data').item.json.fullName }}",
        "resource": "person",
        "additionalFields": {
          "email": [
            "={{ $('\ud83d\udcca Extract Subscriber Data').item.json.email }}"
          ]
        }
      },
      "credentials": {
        "pipedriveApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4047aced-ec20-4d6b-9173-1062fa71a06e",
      "name": "\ud83d\udcbc Create High-Value Deal",
      "type": "n8n-nodes-base.pipedrive",
      "position": [
        832,
        80
      ],
      "parameters": {
        "title": "=High Value Lead - {{ $('\ud83d\udcca Extract Subscriber Data').item.json.fullName }}",
        "person_id": null,
        "associateWith": "person",
        "additionalFields": {
          "value": "={{ Math.round($json.leadScore * 10) }}",
          "status": "open",
          "currency": "USD"
        }
      },
      "credentials": {
        "pipedriveApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1e8ea15c-3d79-4c75-acdb-9ea1b71a7feb",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        -112
      ],
      "parameters": {
        "color": 5,
        "width": 448,
        "height": 896,
        "content": "## 1. Lead Capture & Subscriber Data Extraction\n\n*\ud83d\udce9 Mailchimp Subscriber Trigger listens for new subscribers from the selected Mailchimp list.\n\n\ud83d\udcca Extract Subscriber Data processes the raw payload, extracting structured details like first name, last name, email, list ID, and subscription timestamp.\n\n\ud83d\udc49 Together, these two nodes handle the initial capture of leads and prepare them for enrichment.*"
      },
      "typeVersion": 1
    },
    {
      "id": "49498336-18bc-408d-92e2-4c06ce6f6f56",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -16,
        -112
      ],
      "parameters": {
        "color": 3,
        "width": 528,
        "height": 896,
        "content": "## 2. AI-Powered Lead Enrichment\n\n*\ud83e\udd16 Lead Enrichment AI uses AI to enrich subscriber data, predicting company, job title, industry, intent, LinkedIn URL, and assigning a lead score.\n\n\ud83d\udd0e Parse & Merge Enrichment parses AI output, merges it with the subscriber's base data, and ensures defaults are set if enrichment fails.\n\n\ud83d\udc49 This group forms the AI enrichment layer \u2013 enhancing leads with professional and scoring data for downstream CRM use.*"
      },
      "typeVersion": 1
    },
    {
      "id": "9d037fa7-614b-413f-a166-0c30efcd6b7a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        -112
      ],
      "parameters": {
        "color": 4,
        "width": 480,
        "height": 368,
        "content": "## 3. Lead Qualification & Scoring\n\n*\ud83d\udc8e High-Value Lead Check evaluates the lead score and determines if it meets the high-value threshold (\u226570).\n\n\ud83d\udc49 This acts as the qualification logic to filter out top-priority leads for special handling.*"
      },
      "typeVersion": 1
    },
    {
      "id": "b3befa0e-e2c3-4c49-98db-8276134f2478",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        272
      ],
      "parameters": {
        "width": 480,
        "height": 512,
        "content": "## 4. CRM Sync & Deal Creation\n\n*CRM integration syncs enriched leads to HubSpot & Pipedrive, with automatic deal creation for high-value leads*"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "\ud83e\udde0 OpenAI Model": {
      "ai_languageModel": [
        [
          {
            "node": "\ud83e\udd16 Lead Enrichment AI",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "\ud83e\udd16 Lead Enrichment AI": {
      "main": [
        [
          {
            "node": "\ud83d\udd0e Parse & Merge Enrichment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udcca HubSpot Contact Sync": {
      "main": [
        []
      ]
    },
    "\ud83d\udc8e High-Value Lead Check": {
      "main": [
        [
          {
            "node": "\ud83d\udcbc Create High-Value Deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udc64 Pipedrive Person Create": {
      "main": [
        []
      ]
    },
    "\ud83d\udcca Extract Subscriber Data": {
      "main": [
        [
          {
            "node": "\ud83e\udd16 Lead Enrichment AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udd0e Parse & Merge Enrichment": {
      "main": [
        [
          {
            "node": "\ud83d\udc8e High-Value Lead Check",
            "type": "main",
            "index": 0
          },
          {
            "node": "\ud83d\udcca HubSpot Contact Sync",
            "type": "main",
            "index": 0
          },
          {
            "node": "\ud83d\udc64 Pipedrive Person Create",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udce9 Mailchimp Subscriber Trigger": {
      "main": [
        [
          {
            "node": "\ud83d\udcca Extract Subscriber Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}