{
  "name": "CRM Lead Scoring — Auto Score + Notifikasi Hot Lead",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "score-lead",
        "responseMode": "responseNode"
      },
      "id": "e1b2c3d4-0001-4000-8000-000000000001",
      "name": "Webhook — Data Lead Masuk",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        250,
        300
      ],
      "webhookId": "lead-scoring-webhook"
    },
    {
      "parameters": {
        "jsCode": "// Lead Scoring Logic\nconst lead = $input.first().json.body;\nlet score = 0;\n\n// Budget scoring\nif (lead.budget === 'above_10jt') score += 30;\nelse if (lead.budget === '5jt_10jt') score += 20;\nelse if (lead.budget === '1jt_5jt') score += 10;\n\n// Urgency scoring\nif (lead.urgency === 'asap') score += 25;\nelse if (lead.urgency === '1_bulan') score += 15;\nelse if (lead.urgency === '3_bulan') score += 5;\n\n// Company size scoring\nif (lead.company_size === 'enterprise') score += 20;\nelse if (lead.company_size === 'medium') score += 15;\nelse if (lead.company_size === 'small') score += 10;\n\n// Source scoring\nif (lead.source === 'referral') score += 15;\nelse if (lead.source === 'organic') score += 10;\nelse if (lead.source === 'social') score += 5;\n\n// Determine category\nlet category = 'cold';\nif (score >= 70) category = 'hot';\nelse if (score >= 40) category = 'warm';\n\nreturn [{\n  json: {\n    ...lead,\n    score,\n    category,\n    scored_at: new Date().toISOString()\n  }\n}];"
      },
      "id": "e1b2c3d4-0002-4000-8000-000000000002",
      "name": "Code — Hitung Skor Lead",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "=GANTI_DENGAN_SPREADSHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Scored Leads"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        }
      },
      "id": "e1b2c3d4-0003-4000-8000-000000000003",
      "name": "Google Sheets — Simpan Skor",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        750,
        200
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": ""
          },
          "conditions": [
            {
              "id": "cond1",
              "leftValue": "={{ $json.category }}",
              "rightValue": "hot",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "e1b2c3d4-0004-4000-8000-000000000004",
      "name": "IF — Lead Hot?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        750,
        400
      ]
    },
    {
      "parameters": {
        "sendTo": "=GANTI_DENGAN_EMAIL_SALES",
        "subject": "=HOT LEAD! {{ $json.nama }} (Skor: {{ $json.score }})",
        "message": "=Ada lead baru dengan skor tinggi!\n\nNama: {{ $json.nama }}\nEmail: {{ $json.email }}\nTelepon: {{ $json.phone }}\nBudget: {{ $json.budget }}\nUrgensi: {{ $json.urgency }}\nSkor: {{ $json.score }}/100\n\nSegera follow up!"
      },
      "id": "e1b2c3d4-0005-4000-8000-000000000005",
      "name": "Email — Notifikasi Sales",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1000,
        350
      ]
    },
    {
      "parameters": {
        "respondWith": "text",
        "responseBody": "={{ JSON.stringify({ status: \"ok\", score: $json.score, category: $json.category }) }}"
      },
      "id": "e1b2c3d4-0006-4000-8000-000000000006",
      "name": "Respond — Return Skor",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1000,
        500
      ]
    }
  ],
  "connections": {
    "Webhook — Data Lead Masuk": {
      "main": [
        [
          {
            "node": "Code — Hitung Skor Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code — Hitung Skor Lead": {
      "main": [
        [
          {
            "node": "Google Sheets — Simpan Skor",
            "type": "main",
            "index": 0
          },
          {
            "node": "IF — Lead Hot?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF — Lead Hot?": {
      "main": [
        [
          {
            "node": "Email — Notifikasi Sales",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond — Return Skor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email — Notifikasi Sales": {
      "main": [
        [
          {
            "node": "Respond — Return Skor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateId": "mcsyauqi-lead-scoring-05"
  }
}