{
  "id": "JZ8C3IFRtHrntshw",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Lead Scoring Pipeline with Telegram and Box",
  "tags": [],
  "nodes": [
    {
      "id": "7f75e700-cc72-42b5-b324-06349c0040d9",
      "name": "\u26a1\ufe0f Lead Scoring Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -576,
        32
      ],
      "parameters": {
        "width": 550,
        "height": 866,
        "content": "## How it works\nThis workflow listens for new lead submissions via a secure webhook, normalises field names and validates that the essential data is present. If the submission is complete, it enriches the lead with data from Clearbit, merges the results, and computes a numeric lead-score using a simple but extensible algorithm. Depending on the score, the lead is routed down either a *qualified* or *unqualified* path.  All lead details are serialised as JSON files and uploaded to dedicated Box folders.  Finally, the appropriate Telegram channel is notified so that Sales or Marketing can act immediately.\n\n## Setup steps\n1.  Add your Clearbit API credential under **Credentials \u2192 Clearbit API**.\n2.  Add a **Box OAuth2** credential and share the target folders\u2019 IDs as environment variables `BOX_QUALIFIED_FOLDER_ID` and `BOX_UNQUALIFIED_FOLDER_ID`.\n3.  Create a Telegram bot and add **Telegram Bot API** credentials, then export `TELEGRAM_SALES_CHAT_ID`, `TELEGRAM_MARKETING_CHAT_ID`, and `TELEGRAM_OPS_CHAT_ID`.\n4.  Deploy the workflow; copy the generated webhook URL into your form provider.\n5.  Adjust the score threshold in the *Qualified Lead?* IF node if required.\n6.  Test the workflow with a sample submission and confirm messages appear in Telegram.\n7.  Activate the workflow once end-to-end validation succeeds."
      },
      "typeVersion": 1
    },
    {
      "id": "4b5c7db8-a498-4658-875c-d1faa40278e7",
      "name": "\ud83d\udce5 Intake & Validation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 450,
        "height": 830,
        "content": "## Intake & Validation\nThis group handles all incoming lead data.  The **Lead Form Webhook** node receives raw submissions from any external form provider and forwards them to **Normalize Lead Data**, which standardises key field names so the rest of the workflow can rely on a predictable payload.  A short JavaScript routine in **Validate Required Fields** checks for the presence of an email and company name\u2014both mandatory for enrichment and scoring.  The ensuing **Has Required Fields?** IF node cleanly separates valid and invalid leads.  Invalid submissions trigger an immediate Telegram alert so the marketing team can fix form or user issues without polluting your CRM, while valid leads progress to enrichment."
      },
      "typeVersion": 1
    },
    {
      "id": "ce618659-25cf-400b-a5b7-22ae0db72b53",
      "name": "\ud83e\udde0 Enrichment & Scoring",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 738,
        "height": 830,
        "content": "## Enrichment & Scoring\nValid leads are enriched with Clearbit\u2019s Combined Find endpoint, which appends firmographic and demographic insights.  The **Merge Enriched Data** node combines the original submission and Clearbit data by index, yielding a single, rich JSON object.  In **Calculate Lead Score** we assign points based on factors such as company size, email validity, and social handles.  The following **Prepare Lead Record** node stamps a status and timestamp, ensuring downstream systems have clear context.  This section is the ideal place to extend logic\u2014for example, pull additional signals or adjust weighting factors\u2014to match your organisation\u2019s lead-qualification model."
      },
      "typeVersion": 1
    },
    {
      "id": "41fb2512-4250-4b67-b877-cbdcc18e4b77",
      "name": "\ud83d\udea6 Qualification & Routing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1280,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 738,
        "height": 814,
        "content": "## Qualification & Routing\nA simple threshold-based IF node (**Qualified Lead?**) determines whether the lead is hot enough for Sales or should be nurtured by Marketing.  Each branch builds a JSON file, stores it in a dedicated Box folder, and posts a tailored Telegram message.  Qualified leads alert the Sales channel instantly, while unqualified leads land in Marketing\u2019s backlog for further incubation.  Folder separation keeps your Box workspace tidy and access-controlled.  You can fine-tune the score threshold, message copy, or even add CRM integrations here without touching the intake logic."
      },
      "typeVersion": 1
    },
    {
      "id": "a3dac70f-ce3a-42ac-b2b2-ce495fffce30",
      "name": "\ud83d\udee0\ufe0f Error Handling",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2016,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 1010,
        "height": 814,
        "content": "## Error Handling & Ops\nThe **Workflow Error Trigger** node listens for any unhandled exceptions during execution.  When triggered, it pushes a concise error summary to the Operations Telegram channel, ensuring that failures are surfaced and resolved quickly.  You can extend this path with additional logging, incident-management integrations, or auto-retries.  Keeping error handling separate guarantees that production issues do not silently fail, maintaining trust in the automation\u2019s reliability."
      },
      "typeVersion": 1
    },
    {
      "id": "706ae1fc-aaaa-4df5-a4b6-86b27782f0aa",
      "name": "Lead Form Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        128,
        384
      ],
      "parameters": {
        "path": "lead-intake",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "lastNode"
      },
      "typeVersion": 1
    },
    {
      "id": "10a8cb1a-da98-4c70-a020-c3c0cccf677e",
      "name": "Normalize Lead Data",
      "type": "n8n-nodes-base.set",
      "position": [
        336,
        384
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "0966fd6a-ef19-47ec-9f75-c69f246f4084",
      "name": "Validate Required Fields",
      "type": "n8n-nodes-base.code",
      "position": [
        528,
        384
      ],
      "parameters": {
        "jsCode": "// Validate presence of email and company\nconst items = $input.all();\nreturn items.map(item => {\n  const { email, company } = item.json;\n  const valid = !!(email && company);\n  return {\n    json: {\n      ...item.json,\n      validation: {\n        valid,\n        message: valid ? 'OK' : 'Missing required email or company'\n      }\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "c530aa12-9b3c-44f4-9221-b356c0e847bd",
      "name": "Has Required Fields?",
      "type": "n8n-nodes-base.if",
      "position": [
        736,
        384
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.validation.valid }}",
              "operation": "isTrue"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "708e99e6-2216-4128-87fb-786b2a271d1e",
      "name": "Enrich with Clearbit",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        928,
        384
      ],
      "parameters": {
        "url": "https://company.clearbit.com/v2/combined/find?email={{$json.email}}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "clearbitApi"
      },
      "typeVersion": 4.2
    },
    {
      "id": "78425d66-11a6-474b-88b2-ea0ff9fd6bdc",
      "name": "Merge Enriched Data",
      "type": "n8n-nodes-base.merge",
      "position": [
        1136,
        384
      ],
      "parameters": {
        "mode": "mergeByIndex",
        "options": {}
      },
      "typeVersion": 2.1
    },
    {
      "id": "1320b348-137e-4bf8-896b-b8d31f885a18",
      "name": "Calculate Lead Score",
      "type": "n8n-nodes-base.code",
      "position": [
        1328,
        384
      ],
      "parameters": {
        "jsCode": "// Basic lead-scoring example. Adjust weights as needed.\nconst items = $input.all();\nreturn items.map(item => {\n  const data = item.json;\n  let score = 0;\n\n  if (data.company) score += 20;\n\n  const employees = data.enrichment?.company?.metrics?.employees || data.enrichment?.company?.employees;\n  if (employees) {\n    if (employees > 500) score += 30;\n    else if (employees > 100) score += 20;\n    else score += 10;\n  }\n\n  if (data.enrichment?.person?.linkedin?.handle) score += 20;\n  if (/^.+@.+\\..+$/.test(data.email)) score += 10;\n\n  return {\n    json: {\n      ...data,\n      leadScore: score\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "6372ed09-c458-483c-a8a5-ee5316a2c1f2",
      "name": "Prepare Lead Record",
      "type": "n8n-nodes-base.set",
      "position": [
        1536,
        384
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "6fc67a41-d525-4609-a128-c27bc0c08cde",
      "name": "Qualified Lead?",
      "type": "n8n-nodes-base.if",
      "position": [
        1728,
        384
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.leadScore }}",
              "value2": 70,
              "operation": "largerEqual"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "6c94f31a-35da-4f2e-b5d0-d9d4afb3e389",
      "name": "Build Lead JSON (Qualified)",
      "type": "n8n-nodes-base.code",
      "position": [
        2144,
        304
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nreturn items.map(item => {\n  const fileName = `lead_${Date.now()}_qualified.json`;\n  return {\n    json: {\n      ...item.json,\n      fileName,\n      fileContent: JSON.stringify(item.json, null, 2)\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "2541e981-8218-4a32-bbe6-6b1606ad2139",
      "name": "Upload to Box (Qualified)",
      "type": "n8n-nodes-base.box",
      "position": [
        2336,
        288
      ],
      "parameters": {
        "fileName": "={{ $json.fileName }}",
        "fileContent": "={{ $json.fileContent }}"
      },
      "typeVersion": 1
    },
    {
      "id": "34dc72fb-71d8-4c43-8d6f-e5e943710e8c",
      "name": "Notify Sales (Qualified)",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2544,
        240
      ],
      "parameters": {
        "text": "\ud83c\udf89 New qualified lead: {{$json.firstName}} {{$json.lastName}} (Score {{$json.leadScore}}). Check Box for details.",
        "chatId": "={{ $env.TELEGRAM_SALES_CHAT_ID || 'YOUR_CHAT_ID' }}",
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "b531b854-c3cc-461c-903b-c2af2c48cee9",
      "name": "Build Lead JSON (Unqualified)",
      "type": "n8n-nodes-base.code",
      "position": [
        2144,
        528
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nreturn items.map(item => {\n  const fileName = `lead_${Date.now()}_unqualified.json`;\n  return {\n    json: {\n      ...item.json,\n      fileName,\n      fileContent: JSON.stringify(item.json, null, 2)\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "76191d8f-2cfe-4b89-a222-e21383130aa0",
      "name": "Upload to Box (Unqualified)",
      "type": "n8n-nodes-base.box",
      "position": [
        2336,
        528
      ],
      "parameters": {
        "fileName": "={{ $json.fileName }}",
        "fileContent": "={{ $json.fileContent }}"
      },
      "typeVersion": 1
    },
    {
      "id": "9c1d1cd2-aeb4-4b62-a9c9-72e7151bdbc4",
      "name": "Notify Marketing (Unqualified)",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2608,
        528
      ],
      "parameters": {
        "text": "\u2139\ufe0f New unqualified lead: {{$json.firstName}} {{$json.lastName}} (Score {{$json.leadScore}}). Stored in Box.",
        "chatId": "={{ $env.TELEGRAM_MARKETING_CHAT_ID || 'YOUR_CHAT_ID' }}",
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "21f2bab1-9202-449f-be8f-f1a410903ca5",
      "name": "Notify Marketing (Invalid Submission)",
      "type": "n8n-nodes-base.telegram",
      "position": [
        928,
        592
      ],
      "parameters": {
        "text": "\u2757\ufe0f Received invalid lead submission. Reason: {{$json.validation.message}}",
        "chatId": "={{ $env.TELEGRAM_MARKETING_CHAT_ID || 'YOUR_CHAT_ID' }}",
        "additionalFields": {}
      },
      "typeVersion": 1.2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "715b9b68-addc-42c5-931c-2774276ac682",
  "connections": {
    "Qualified Lead?": {
      "main": [
        [
          {
            "node": "Build Lead JSON (Qualified)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Build Lead JSON (Unqualified)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Form Webhook": {
      "main": [
        [
          {
            "node": "Normalize Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Enriched Data": {
      "main": [
        [
          {
            "node": "Calculate Lead Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Lead Data": {
      "main": [
        [
          {
            "node": "Validate Required Fields",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge Enriched Data",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Prepare Lead Record": {
      "main": [
        [
          {
            "node": "Qualified Lead?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Lead Score": {
      "main": [
        [
          {
            "node": "Prepare Lead Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enrich with Clearbit": {
      "main": [
        [
          {
            "node": "Merge Enriched Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Required Fields?": {
      "main": [
        [
          {
            "node": "Enrich with Clearbit",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Notify Marketing (Invalid Submission)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Required Fields": {
      "main": [
        [
          {
            "node": "Has Required Fields?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge Enriched Data",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Upload to Box (Qualified)": {
      "main": [
        [
          {
            "node": "Notify Sales (Qualified)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Lead JSON (Qualified)": {
      "main": [
        [
          {
            "node": "Upload to Box (Qualified)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Box (Unqualified)": {
      "main": [
        [
          {
            "node": "Notify Marketing (Unqualified)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Lead JSON (Unqualified)": {
      "main": [
        [
          {
            "node": "Upload to Box (Unqualified)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}