{
  "name": "Lunexo – Lead to Telegram Notifier",
  "nodes": [
    {
      "parameters": {
        "content": "## Lead to Telegram Notifier\n\n**What it does:** Receives lead submissions via webhook, scores them based on message length and urgency keywords, then sends a formatted Telegram notification with a visual score bar.\n\n**Setup (~5 min):**\n1. Create a Telegram bot via @BotFather\n2. Add your Telegram Bot API credentials\n3. Change `YOUR_TELEGRAM_CHAT_ID` in the Code node\n4. Activate the workflow\n5. Point your lead form to the webhook URL\n\n**Variables to change:**\n- `YOUR_TELEGRAM_CHAT_ID` in Code node\n- Scoring keywords (optional)",
        "height": 300,
        "width": 350,
        "color": 5
      },
      "id": "e4f5a6b7-c8d9-0123-defa-400000000001",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [40, 80]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "telegram-lead",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "e4f5a6b7-c8d9-0123-defa-400000000002",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300],
      "webhookId": "e4f5a6b7-c8d9-0123-defa-400000000010"
    },
    {
      "parameters": {
        "jsCode": "const input = $input.first().json;\nconst body = input.body || input;\nconst name = body.name || body.fullName || 'Unknown';\nconst email = body.email || '';\nconst phone = body.phone || body.tel || '';\nconst service = body.service || 'Not specified';\nconst message = body.message || body.text || '';\n\n// Lead scoring\nlet score = 0;\nconst words = message.trim().split(/\\s+/).filter(w => w.length > 0);\nscore += Math.min(words.length, 10); // up to 10 points for message length\n\nconst urgencyKeywords = ['urgent','asap','immediately','budget','enterprise'];\nconst lowerMsg = message.toLowerCase();\nfor (const kw of urgencyKeywords) {\n  if (lowerMsg.includes(kw)) score += 2;\n}\n\n// Cap score at 20\nscore = Math.min(score, 20);\n\n// Urgency hint\nlet urgency = 'Normal';\nif (score >= 14) urgency = 'HIGH';\nelse if (score >= 8) urgency = 'Medium';\n\n// Score bar (visual)\nconst filled = Math.round(score / 2);\nconst empty = 10 - filled;\nconst scoreBar = '\\u2588'.repeat(filled) + '\\u2591'.repeat(empty);\n\n// Telegram markdown message\nconst chatId = 'YOUR_TELEGRAM_CHAT_ID';\nconst telegramText = `\\ud83d\\udce8 *New Lead Received*\\n\\n`\n  + `*Name:* ${name}\\n`\n  + `*Email:* ${email}\\n`\n  + `*Phone:* ${phone || 'N/A'}\\n`\n  + `*Service:* ${service}\\n\\n`\n  + `*Message:*\\n${message || 'No message provided'}\\n\\n`\n  + `*Lead Score:* ${score}/20 ${urgency}\\n`\n  + `\\`${scoreBar}\\` ${score}/20\\n\\n`\n  + `_Urgency: ${urgency}_`;\n\nreturn [{ json: { name, email, phone, service, message, score, urgency, chatId, telegramText } }];"
      },
      "id": "e4f5a6b7-c8d9-0123-defa-400000000003",
      "name": "Extract & Score Lead",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "e4f5a6b7-c8d9-0123-defa-400000000020",
              "leftValue": "={{ $json.email }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "name": "filter.operator.notEmpty"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "e4f5a6b7-c8d9-0123-defa-400000000004",
      "name": "IF Valid Data",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [680, 300]
    },
    {
      "parameters": {
        "chatId": "={{ $json.chatId }}",
        "text": "={{ $json.telegramText }}",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "id": "e4f5a6b7-c8d9-0123-defa-400000000005",
      "name": "Send Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [900, 200],
      "credentials": {
        "telegramApi": {
          "id": "CHANGE_ME",
          "name": "Your Telegram Bot"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true, message: 'Lead received and notification sent.', score: $json.score, urgency: $json.urgency }) }}",
        "options": {}
      },
      "id": "e4f5a6b7-c8d9-0123-defa-400000000006",
      "name": "Respond Success",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [1120, 200]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: false, error: 'Missing required fields. Email is required.' }) }}",
        "options": {
          "responseCode": 400
        }
      },
      "id": "e4f5a6b7-c8d9-0123-defa-400000000007",
      "name": "Respond Error",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [900, 420]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Extract & Score Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract & Score Lead": {
      "main": [
        [
          {
            "node": "IF Valid Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Valid Data": {
      "main": [
        [
          {
            "node": "Send Telegram",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Telegram": {
      "main": [
        [
          {
            "node": "Respond Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e4f5a6b7-c8d9-0123-defa-400000000099",
  "meta": {
    "templateCredsSetupCompleted": false,
    "instanceId": "lunexo"
  },
  "pinData": {},
  "staticData": null,
  "tags": [
    { "name": "Lunexo" },
    { "name": "Telegram" },
    { "name": "Lead" }
  ]
}
