{
  "name": "AI Lead Qualifier — Score, Route & Log Inbound Leads",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "lead-intake",
        "options": {
          "responseData": "allEntries"
        }
      },
      "id": "a1f2c3d4-1111-4a2b-9c3d-0e1f2a3b4c5d",
      "name": "Webhook: New Lead",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [-200, 300],
      "webhookId": "a1f2c3d4-1111-4a2b-9c3d-0e1f2a3b4c5d"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You are a B2B lead qualification analyst. Score inbound leads from 1-10 based on fit and intent.\n\nScoring guide:\n- 9-10: clear buying intent, budget mentioned or implied, company size 50+, decision-maker title\n- 7-8: strong fit, specific use case described, mid-size company or senior title\n- 4-6: plausible fit but vague message, small company, junior title, or no use case\n- 1-3: student, job seeker, spam, competitor research, or no business context\n\nRespond ONLY with valid JSON, no markdown fences, exactly this shape:\n{\"score\": <integer 1-10>, \"summary\": \"<one sentence describing the lead>\", \"reason\": \"<one sentence justifying the score>\"}"
            },
            {
              "role": "user",
              "content": "=Qualify this lead:\nName: {{ $json.body.name }}\nEmail: {{ $json.body.email }}\nCompany: {{ $json.body.company }}\nJob title: {{ $json.body.title }}\nCompany size: {{ $json.body.company_size }}\nMessage: {{ $json.body.message }}"
            }
          ]
        },
        "jsonOutput": true,
        "options": {
          "temperature": 0.2
        }
      },
      "id": "b2e3d4f5-2222-4b3c-8d4e-1f2a3b4c5d6e",
      "name": "OpenAI: Score Lead",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [40, 300],
      "credentials": {
        "openAiApi": {
          "id": "YOUR_OPENAI_CREDENTIAL",
          "name": "YOUR_OPENAI_CREDENTIAL"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Normalize the LLM output and merge it with the original lead fields\nconst ai = $input.first().json.message?.content ?? $input.first().json;\nconst lead = $('Webhook: New Lead').first().json.body;\n\nreturn [{\n  json: {\n    name: lead.name,\n    email: lead.email,\n    company: lead.company,\n    title: lead.title,\n    company_size: lead.company_size,\n    message: lead.message,\n    score: Number(ai.score) || 0,\n    summary: ai.summary || '',\n    reason: ai.reason || '',\n    scored_at: new Date().toISOString(),\n  },\n}];"
      },
      "id": "c3f4e5a6-3333-4c4d-9e5f-2a3b4c5d6e7f",
      "name": "Code: Merge Score",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [280, 300]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "d4a5b6c7-4444-4d5e-8f6a-3b4c5d6e7f8a",
              "leftValue": "={{ $json.score }}",
              "rightValue": 7,
              "operator": {
                "type": "number",
                "operation": "gte"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "d4a5b6c7-4444-4d5e-8f6a-3b4c5d6e7f8b",
      "name": "IF: Score >= 7",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [520, 300]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "#sales-hot-leads",
          "mode": "name"
        },
        "text": "=:fire: *Hot lead: {{ $json.name }}* ({{ $json.company }}, {{ $json.title }})\nScore: *{{ $json.score }}/10*\n{{ $json.summary }}\n_Why:_ {{ $json.reason }}\nEmail: {{ $json.email }}",
        "otherOptions": {}
      },
      "id": "e5b6c7d8-5555-4e6f-9a7b-4c5d6e7f8a9b",
      "name": "Slack: Notify Sales",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [780, 180],
      "credentials": {
        "slackApi": {
          "id": "YOUR_SLACK_CREDENTIAL",
          "name": "YOUR_SLACK_CREDENTIAL"
        }
      }
    },
    {
      "parameters": {
        "resource": "contact",
        "email": "={{ $json.email }}",
        "additionalFields": {
          "firstName": "={{ $json.name.split(' ')[0] }}",
          "lastName": "={{ $json.name.split(' ').slice(1).join(' ') }}",
          "companyName": "={{ $json.company }}",
          "jobTitle": "={{ $json.title }}"
        }
      },
      "id": "f6c7d8e9-6666-4f7a-8b8c-5d6e7f8a9b0c",
      "name": "HubSpot: Create Contact",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.1,
      "position": [780, 360],
      "credentials": {
        "hubspotApi": {
          "id": "YOUR_HUBSPOT_CREDENTIAL",
          "name": "YOUR_HUBSPOT_CREDENTIAL"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "YOUR_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Low Priority Leads",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Date": "={{ $json.scored_at }}",
            "Name": "={{ $json.name }}",
            "Email": "={{ $json.email }}",
            "Company": "={{ $json.company }}",
            "Score": "={{ $json.score }}",
            "Summary": "={{ $json.summary }}",
            "Reason": "={{ $json.reason }}"
          }
        },
        "options": {}
      },
      "id": "a7d8e9f0-7777-4a8b-9c9d-6e7f8a9b0c1d",
      "name": "Google Sheets: Log Lead",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [780, 540],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "YOUR_GOOGLE_SHEETS_CREDENTIAL",
          "name": "YOUR_GOOGLE_SHEETS_CREDENTIAL"
        }
      }
    }
  ],
  "connections": {
    "Webhook: New Lead": {
      "main": [
        [
          {
            "node": "OpenAI: Score Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI: Score Lead": {
      "main": [
        [
          {
            "node": "Code: Merge Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Merge Score": {
      "main": [
        [
          {
            "node": "IF: Score >= 7",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF: Score >= 7": {
      "main": [
        [
          {
            "node": "Slack: Notify Sales",
            "type": "main",
            "index": 0
          },
          {
            "node": "HubSpot: Create Contact",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Google Sheets: Log Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
