{
  "nodes": [
    {
      "id": "e134a073-3ab5-4ce1-9043-b93238cd7c10",
      "name": "Webhook Receive Lead",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1184,
        -176
      ],
      "webhookId": "422dc826-5661-4f75-8995-09ccf9e4773c",
      "parameters": {
        "path": "incoming-lead",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "lastNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "51751392-d4ee-47f7-aa2a-af98b19033cd",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "position": [
        1184,
        16
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "SCORE_THRESHOLD",
              "type": "number",
              "value": 7
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c878ffac-d4a7-4f53-9f3e-9a01d6fedcee",
      "name": "Manual Test",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        1184,
        176
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "2523c78d-8eb2-47a2-9a58-40658d77b5db",
      "name": "Normalize Lead Data",
      "type": "n8n-nodes-base.set",
      "position": [
        1616,
        -64
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "name",
              "type": "string",
              "value": "={{ $json.body?.name ?? $json.name ?? 'Lead' }}"
            },
            {
              "id": "2",
              "name": "email",
              "type": "string",
              "value": "={{ $json.body?.email ?? $json.email ?? '' }}"
            },
            {
              "id": "3",
              "name": "company",
              "type": "string",
              "value": "={{ $json.body?.company ?? $json.company ?? '' }}"
            },
            {
              "id": "4",
              "name": "website",
              "type": "string",
              "value": "={{ $json.body?.website ?? $json.website ?? '' }}"
            },
            {
              "id": "5",
              "name": "SCORE_THRESHOLD",
              "type": "number",
              "value": "={{ $json.SCORE_THRESHOLD ?? 7 }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "aae6950d-861a-41ed-a579-ac612d99b2cd",
      "name": "AI Score Lead",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1760,
        -64
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/chat/completions",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"gpt-4o-mini\",\n  \"messages\": [{\n    \"role\": \"user\",\n    \"content\": \"Score this B2B lead from 1-10. Reply with ONLY the number.\\n\\nName: {{ $json.name }}\\nEmail: {{ $json.email }}\\nCompany: {{ $json.company }}\\nWebsite: {{ $json.website }}\"\n  }],\n  \"temperature\": 0.3,\n  \"max_tokens\": 10\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi"
      },
      "typeVersion": 4.2
    },
    {
      "id": "7326f10a-a44c-4cd9-98ca-378d3c740dac",
      "name": "Parse Score",
      "type": "n8n-nodes-base.code",
      "position": [
        1904,
        -32
      ],
      "parameters": {
        "jsCode": "const resp = $input.first().json;\nconst content = resp.choices?.[0]?.message?.content ?? resp.message?.content ?? '5';\nconst score = Math.min(10, Math.max(1, parseInt(String(content).match(/\\d+/)?.[0] || '5') || 5));\nlet lead = {};\ntry { lead = $('Normalize Lead Data').first().json; } catch (_) {}\nif (!lead || Object.keys(lead).length === 0) { try { lead = $('Sample Data').first().json; } catch (_) {} }\nconst threshold = lead.SCORE_THRESHOLD ?? 7;\nreturn { json: { ...lead, score, status: score >= threshold ? 'hot' : 'nurture', action: score >= threshold ? 'immediate_followup' : 'add_to_sequence', processed: true } };"
      },
      "typeVersion": 2
    },
    {
      "id": "a260869e-574a-4771-8fd5-dc9afc96d42d",
      "name": "Is Hot Lead?",
      "type": "n8n-nodes-base.if",
      "position": [
        2128,
        -32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "caseSensitive": true
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.score }}",
              "rightValue": "={{ $json.SCORE_THRESHOLD ?? 7 }}"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "868d32ba-fa5e-4756-b938-ffe7c935810a",
      "name": "Hot Lead",
      "type": "n8n-nodes-base.set",
      "position": [
        2336,
        -128
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "status",
              "type": "string",
              "value": "hot"
            },
            {
              "id": "2",
              "name": "action",
              "type": "string",
              "value": "immediate_followup"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a5dbb376-57f2-4b0f-8849-d31dda75b6fb",
      "name": "Nurture Lead",
      "type": "n8n-nodes-base.set",
      "position": [
        2336,
        80
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "status",
              "type": "string",
              "value": "nurture"
            },
            {
              "id": "2",
              "name": "action",
              "type": "string",
              "value": "add_to_sequence"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2b19f883-5abc-4ade-8bb3-62a0522bd05e",
      "name": "Merge Output",
      "type": "n8n-nodes-base.merge",
      "position": [
        2560,
        -32
      ],
      "parameters": {},
      "typeVersion": 3
    }
  ],
  "connections": {
    "Config": {
      "main": [
        [
          {
            "node": "Webhook Receive Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Test": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook Receive Lead": {
      "main": [
        [
          {
            "node": "Normalize Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Lead Data": {
      "main": [
        [
          {
            "node": "AI Score Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Score Lead": {
      "main": [
        [
          {
            "node": "Parse Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Score": {
      "main": [
        [
          {
            "node": "Is Hot Lead?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Hot Lead?": {
      "main": [
        [
          {
            "node": "Hot Lead",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Nurture Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hot Lead": {
      "main": [
        [
          {
            "node": "Merge Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Nurture Lead": {
      "main": [
        [
          {
            "node": "Merge Output",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}