{
  "name": "Lead Scoring — Firmographic & Technographic Fit",
  "nodes": [
    {
      "parameters": {
        "eventsUi": {
          "eventValues": [
            {
              "name": "contact.propertyChange",
              "property": "hs_analytics_source"
            }
          ]
        }
      },
      "id": "hubspot-trigger",
      "name": "HubSpot Trigger",
      "type": "n8n-nodes-base.hubspotTrigger",
      "typeVersion": 1,
      "position": [0, 0],
      "webhookId": "hubspot-trigger-id",
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.hubapi.com/crm/v3/objects/contacts/{{ $json.objectId }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotApi",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "properties",
              "value": "firstname,lastname,jobtitle,company,numberofemployees,industry,hs_analytics_source"
            }
          ]
        },
        "options": {}
      },
      "id": "fetch-contact",
      "name": "Fetch Contact",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [220, 0],
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const contact = $('Fetch Contact').first().json.properties;\n\nlet score = 0;\n\n// --- Company size scoring (0-30 points) ---\nconst employees = parseInt(contact.numberofemployees || '0');\nif (employees >= 200 && employees <= 2000) score += 30;\nelse if (employees >= 50 && employees < 200) score += 20;\nelse if (employees >= 2000 && employees <= 10000) score += 15;\nelse if (employees > 0) score += 5;\n\n// --- Industry scoring (0-25 points) ---\nconst industry = (contact.industry || '').toLowerCase();\nconst idealIndustries = ['saas', 'technology', 'software', 'computer software'];\nconst goodIndustries = ['financial services', 'consulting', 'marketing'];\nif (idealIndustries.includes(industry)) score += 25;\nelse if (goodIndustries.includes(industry)) score += 15;\nelse if (industry) score += 5;\n\n// --- Seniority scoring (0-30 points) ---\nconst title = (contact.jobtitle || '').toLowerCase();\nconst cSuite = ['ceo', 'cto', 'cfo', 'coo', 'cmo', 'cro', 'chief'];\nconst vp = ['vp', 'vice president', 'head of'];\nconst director = ['director', 'senior director'];\nconst manager = ['manager', 'senior manager', 'lead'];\n\nif (cSuite.some(t => title.includes(t))) score += 30;\nelse if (vp.some(t => title.includes(t))) score += 25;\nelse if (director.some(t => title.includes(t))) score += 20;\nelse if (manager.some(t => title.includes(t))) score += 10;\n\n// --- Lead source scoring (0-15 points) ---\nconst source = (contact.hs_analytics_source || '').toLowerCase();\nconst sourceScores = {\n  'organic_search': 15,\n  'direct_traffic': 12,\n  'referrals': 10,\n  'paid_search': 8,\n  'social_media': 5,\n  'email_marketing': 5,\n};\nscore += sourceScores[source] || 0;\n\nreturn [{\n  json: {\n    contactId: $('HubSpot Trigger').first().json.objectId,\n    score: Math.min(score, 100),\n    name: `${contact.firstname || ''} ${contact.lastname || ''}`.trim(),\n    title: contact.jobtitle,\n    company: contact.company,\n    employees,\n  }\n}];"
      },
      "id": "score-contact",
      "name": "Score Contact",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [440, 0]
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "=https://api.hubapi.com/crm/v3/objects/contacts/{{ $json.contactId }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={ \"properties\": { \"icp_fit_score\": \"{{ $json.score }}\" } }",
        "options": {}
      },
      "id": "write-score",
      "name": "Write Score to HubSpot",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [660, 0],
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "conditions": [
            {
              "leftValue": "={{ $json.score }}",
              "rightValue": 70,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "high-score-check",
      "name": "Score > 70?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [880, 0]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "high-fit-leads",
          "mode": "name"
        },
        "messageType": "block",
        "blocksUi": "={\n  \"blocks\": [\n    {\n      \"type\": \"section\",\n      \"text\": {\n        \"type\": \"mrkdwn\",\n        \"text\": \"🎯 *High-Fit Lead Scored*\\n*\" + $json.name + \"* — \" + ($json.title || 'No title') + \" at \" + ($json.company || 'Unknown') + \" (\" + $json.employees + \" employees)\\nScore: *\" + $json.score + \"/100*\"\n      }\n    }\n  ]\n}",
        "otherOptions": {
          "unfurl_links": false
        }
      },
      "id": "notify-slack",
      "name": "Notify High-Fit Lead",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [1100, 0],
      "credentials": {
        "slackApi": {
          "id": "credential-id",
          "name": "Slack API"
        }
      }
    }
  ],
  "connections": {
    "HubSpot Trigger": {
      "main": [
        [
          {
            "node": "Fetch Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Contact": {
      "main": [
        [
          {
            "node": "Score Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score Contact": {
      "main": [
        [
          {
            "node": "Write Score to HubSpot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Score to HubSpot": {
      "main": [
        [
          {
            "node": "Score > 70?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score > 70?": {
      "main": [
        [
          {
            "node": "Notify High-Fit Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "active": false,
  "meta": {
    "instanceId": "",
    "templateId": "revi-lead-scoring"
  }
}