{
  "name": "Automated Lead Scoring (FlowsOnDemand)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "lead-scoring",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "node-webhook",
      "name": "New Lead Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [240, 300]
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Simple weighted lead-scoring model.\n// Expects incoming fields: company_size, industry, visited_pricing, requested_demo, email.\nconst data = $input.item.json;\n\nlet score = 0;\n\n// Company size weighting\nconst size = Number(data.company_size) || 0;\nif (size >= 200) score += 30;\nelse if (size >= 50) score += 20;\nelse if (size >= 10) score += 10;\n\n// Industry fit\nconst hotIndustries = ['saas', 'software', 'ecommerce', 'agency', 'fintech'];\nif (data.industry && hotIndustries.includes(String(data.industry).toLowerCase())) {\n  score += 20;\n}\n\n// Behavioral signals\nif (data.visited_pricing === true || data.visited_pricing === 'true') score += 25;\nif (data.requested_demo === true || data.requested_demo === 'true') score += 35;\n\n// Cap at 100\nscore = Math.min(100, score);\n\nlet grade = 'cold';\nif (score >= 70) grade = 'hot';\nelse if (score >= 40) grade = 'warm';\n\nreturn {\n  json: {\n    ...data,\n    lead_score: score,\n    lead_grade: grade,\n    is_hot: score >= 70\n  }\n};"
      },
      "id": "node-score",
      "name": "Score Lead",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
          "conditions": [
            {
              "id": "cond-hot",
              "leftValue": "={{ $json.is_hot }}",
              "rightValue": true,
              "operator": { "type": "boolean", "operation": "true", "singleValue": true }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "node-if",
      "name": "Is Hot Lead?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [680, 300]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": { "__rl": true, "value": "#sales", "mode": "name" },
        "text": "=:fire: *Hot lead* — score {{ $json.lead_score }}/100\\nEmail: {{ $json.email }}\\nIndustry: {{ $json.industry }}\\nCompany size: {{ $json.company_size }}",
        "otherOptions": {}
      },
      "id": "node-slack",
      "name": "Alert Sales in Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [920, 200],
      "notesInFlow": true,
      "notes": "Connect your Slack credential and pick the channel."
    },
    {
      "parameters": {
        "resource": "contact",
        "operation": "upsert",
        "email": "={{ $json.email }}",
        "additionalFields": {}
      },
      "id": "node-hubspot",
      "name": "Update HubSpot Score",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2,
      "position": [920, 400],
      "notesInFlow": true,
      "notes": "Map lead_score to a custom HubSpot property. Connect your HubSpot credential."
    }
  ],
  "connections": {
    "New Lead Webhook": { "main": [[{ "node": "Score Lead", "type": "main", "index": 0 }]] },
    "Score Lead": { "main": [[{ "node": "Is Hot Lead?", "type": "main", "index": 0 }]] },
    "Is Hot Lead?": {
      "main": [
        [{ "node": "Alert Sales in Slack", "type": "main", "index": 0 }],
        [{ "node": "Update HubSpot Score", "type": "main", "index": 0 }]
      ]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "pinData": {},
  "meta": { "templatecredsSetupCompleted": false },
  "tags": [{ "name": "FlowsOnDemand" }]
}
