{
  "name": "Lead intake: score and route new leads",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "lead-intake",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "61f6cafe-f3dd-5139-9630-74b66dd5e0d6",
      "name": "New form submission",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "notes": "Point your website form, Typeform or ad lead form at this URL.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "name",
              "value": "={{ ($json.body.name ?? '').trim() }}",
              "type": "string"
            },
            {
              "id": "2",
              "name": "email",
              "value": "={{ ($json.body.email ?? '').trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "3",
              "name": "company",
              "value": "={{ $json.body.company ?? '' }}",
              "type": "string"
            },
            {
              "id": "4",
              "name": "message",
              "value": "={{ $json.body.message ?? '' }}",
              "type": "string"
            },
            {
              "id": "5",
              "name": "source",
              "value": "={{ $json.body.utm_source ?? 'website' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "458ddb71-305c-55ef-8bb2-5ef5052fda19",
      "name": "Clean up the lead",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.anthropic.com/v1/messages",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "anthropic-version",
              "value": "2023-06-01"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'claude-haiku-5-5', max_tokens: 600, system: \"You qualify inbound B2B leads. Reply with JSON only: {\\\"score\\\": 0-100, \\\"intent\\\": \\\"buy|research|support|spam\\\", \\\"summary\\\": \\\"one sentence\\\", \\\"urgency\\\": \\\"today|this week|later\\\"}.\", messages: [{ role: 'user', content: `Lead: ${$json.name} <${$json.email}> at ${$json.company}. Source: ${$json.source}. Message: ${$json.message}` }] }) }}",
        "options": {
          "timeout": 60000
        }
      },
      "id": "ca040b02-17a1-5fd9-a809-68303ffe4fa5",
      "name": "Score the lead with Claude",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Anthropic API key (header x-api-key)"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Claude replies with JSON text; turn it into fields and keep the original input alongside.\nreturn $input.all().map((item) => {\n  const text = item.json.content?.[0]?.text ?? '{}';\n  const match = text.match(/\\{[\\s\\S]*\\}/);\n  let parsed = {};\n  try { parsed = JSON.parse(match ? match[0] : text); } catch { parsed = { parse_error: true, raw: text }; }\n  return { json: { ...parsed } }; // score, intent, summary, urgency\n});"
      },
      "id": "82e1303c-fd87-595b-8828-a74a986ee52a",
      "name": "Read the score",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "dc7d53df-6491-5c57-b9ed-31740dfe3e61",
              "leftValue": "={{ $json.score }}",
              "rightValue": 70,
              "operator": {
                "type": "number",
                "operation": "gte"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "7642b1c6-0c70-587c-ae5d-d2474681868a",
      "name": "Hot lead?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        880,
        0
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "#sales",
          "mode": "name"
        },
        "text": "=:fire: Hot lead ({{ $json.score }}/100): {{ $('Clean up the lead').item.json.name }} at {{ $('Clean up the lead').item.json.company }}\n{{ $json.summary }}\nReply {{ $json.urgency }}: {{ $('Clean up the lead').item.json.email }}",
        "otherOptions": {}
      },
      "id": "fa47e473-4096-52cd-968a-c02d0ead8d19",
      "name": "Alert sales in Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        1100,
        -120
      ],
      "credentials": {
        "slackApi": {
          "id": "",
          "name": "Slack"
        }
      }
    },
    {
      "parameters": {
        "authentication": "appToken",
        "resource": "contact",
        "operation": "upsert",
        "email": "={{ $('Clean up the lead').item.json.email }}",
        "additionalFields": {
          "firstName": "={{ $('Clean up the lead').item.json.name.split(' ')[0] }}",
          "companyName": "={{ $('Clean up the lead').item.json.company }}",
          "message": "={{ $('Read the score').item.json.summary }}",
          "leadStatus": "={{ $('Read the score').item.json.score >= 70 ? 'OPEN' : 'NEW' }}"
        }
      },
      "id": "62429900-058d-5124-9919-cf0c285b29e0",
      "name": "Add to HubSpot",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2,
      "position": [
        1320,
        0
      ],
      "credentials": {
        "hubspotAppToken": {
          "id": "",
          "name": "HubSpot"
        }
      }
    }
  ],
  "connections": {
    "New form submission": {
      "main": [
        [
          {
            "node": "Clean up the lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean up the lead": {
      "main": [
        [
          {
            "node": "Score the lead with Claude",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score the lead with Claude": {
      "main": [
        [
          {
            "node": "Read the score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read the score": {
      "main": [
        [
          {
            "node": "Hot lead?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hot lead?": {
      "main": [
        [
          {
            "node": "Alert sales in Slack",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add to HubSpot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alert sales in Slack": {
      "main": [
        [
          {
            "node": "Add to HubSpot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "adev": {
      "slug": "lead-intake",
      "service": "ai-automation",
      "needs": [
        "n8n",
        "Anthropic API key",
        "Slack",
        "HubSpot (or swap for your CRM)"
      ],
      "summary": "Every web, ad or Typeform lead is cleaned, scored by Claude and added to the CRM. Hot leads reach the sales channel in under a minute."
    }
  },
  "tags": [
    {
      "name": "adev.build"
    }
  ]
}