{
  "name": "Nodbot - VK Lead Forms to Google Sheets with UTM dedupe",
  "nodes": [
    {
      "parameters": {
        "path": "vk-lead-form-to-sheets",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "0f579c7e-132e-4416-909c-6a70577d7220",
      "name": "VK Lead Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst leadId = String(src.lead_id ?? src.id ?? '').trim();\nif (!leadId) throw new Error('Missing VK lead_id');\n\nconst rawPhone = String(src.phone ?? src.Phone ?? '').trim();\nlet digits = rawPhone.replace(/\\D/g, '');\nif (digits.length === 11 && digits.startsWith('8')) digits = `7${digits.slice(1)}`;\nif (digits.length === 10) digits = `7${digits}`;\nif (!/^7\\d{10}$/.test(digits)) throw new Error(`Invalid VK lead phone: ${rawPhone}`);\n\nconst email = String(src.email ?? '').trim().toLowerCase();\nconst now = new Date().toISOString();\n\nreturn [{\n  json: {\n    row_key: `vk:${leadId}`,\n    dedupe_phone_key: `phone:+${digits}`,\n    lead_id: leadId,\n    phone_raw: rawPhone,\n    phone_normalized: `+${digits}`,\n    name: String(src.name ?? src.first_name ?? 'Новый лид VK').trim(),\n    email,\n    group_id: String(src.group_id ?? ''),\n    form_id: String(src.form_id ?? ''),\n    campaign_id: String(src.campaign_id ?? ''),\n    ad_id: String(src.ad_id ?? ''),\n    utm_source: src.utm_source ?? 'vk',\n    utm_medium: src.utm_medium ?? '',\n    utm_campaign: src.utm_campaign ?? '',\n    utm_content: src.utm_content ?? '',\n    first_seen_at: src.created_at ?? now,\n    updated_at: now,\n    status: 'new'\n  }\n}];"
      },
      "id": "eae87a03-07bf-47c7-963b-fa0484330b52",
      "name": "Normalize VK lead",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {},
      "id": "dcd633b9-3299-4446-9795-bfc3ab8f98ff",
      "name": "Find row in Google Sheets",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {},
      "id": "a98ee552-562e-47ee-9e02-791ee6efb303",
      "name": "Update or append row",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {},
      "id": "00310656-5dc8-4277-a777-022a61afb0c8",
      "name": "Notify manager",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    },
    {
      "parameters": {},
      "id": "9b6d2926-4b20-426b-ae87-3b24925794f4",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 2,
      "position": [
        1400,
        260
      ]
    }
  ],
  "connections": {
    "VK Lead Webhook": {
      "main": [
        [
          {
            "node": "Normalize VK lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize VK lead": {
      "main": [
        [
          {
            "node": "Find row in Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find row in Google Sheets": {
      "main": [
        [
          {
            "node": "Update or append row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update or append row": {
      "main": [
        [
          {
            "node": "Notify manager",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify manager": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "nodbot",
    "production",
    "template"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "a39fc7a6-e60f-4df3-9509-8204c9673e64",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}