{
  "name": "VietlinhAI | Nhận lead landing page, báo Zalo, gửi mail cảm ơn",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "3988de5b-6791-470b-9e42-73f9384d7fa4",
        "options": {
          "allowedOrigins": "https://your-website.com,https://www.your-website.com"
        }
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -1072,
        112
      ],
      "id": "928483ef-367b-4b6a-a0dd-3df958abebdc",
      "name": "Webhook Landing page",
      "webhookId": "eb527841-a099-44c3-afd0-25c66b452254"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.body.website || '' }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              }
            },
            {
              "id": "c2",
              "leftValue": "={{ $json.body.email || '' }}",
              "rightValue": "@",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            },
            {
              "id": "c3",
              "leftValue": "={{ ($json.body.phone || '').replace(/[^0-9]/g, '').length }}",
              "rightValue": 9,
              "operator": {
                "type": "number",
                "operation": "gte"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -848,
        112
      ],
      "id": "4ee50b2a-fcbd-4061-8142-0963549d25b9",
      "name": "Lọc spam & validate"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "s1",
              "name": "user_id",
              "value": "={{ 'lp' + $now.setZone('Asia/Ho_Chi_Minh').toFormat('yyyyMMddHHmmss') + '-' + Math.floor(Math.random() * 900 + 100) }}",
              "type": "string"
            },
            {
              "id": "s2",
              "name": "platform",
              "value": "Landing page",
              "type": "string"
            },
            {
              "id": "s3",
              "name": "customer_name",
              "value": "={{ ($json.body.name || '').trim() || 'Chưa cung cấp' }}",
              "type": "string"
            },
            {
              "id": "s4",
              "name": "phone",
              "value": "={{ ($json.body.phone || '').trim() }}",
              "type": "string"
            },
            {
              "id": "s5",
              "name": "email",
              "value": "={{ ($json.body.email || '').trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "s6",
              "name": "form_sent",
              "value": "Yes",
              "type": "string"
            },
            {
              "id": "s7",
              "name": "form_submitted",
              "value": "Yes",
              "type": "string"
            },
            {
              "id": "s8",
              "name": "created_at",
              "value": "={{ $now.setZone('Asia/Ho_Chi_Minh').toFormat('HH:mm:ss d/M/yyyy') }}",
              "type": "string"
            },
            {
              "id": "s9",
              "name": "status",
              "value": "new",
              "type": "string"
            },
            {
              "id": "s10",
              "name": "conversation_summary",
              "value": "Đăng ký tư vấn từ landing page [TÊN SẢN PHẨM / KHÓA HỌC]",
              "type": "string"
            },
            {
              "id": "s11",
              "name": "customer_need",
              "value": "[TÊN SẢN PHẨM / KHÓA HỌC] ([GIÁ])",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -560,
        0
      ],
      "id": "8e62c44a-c2b6-418a-bfeb-ed04c9abf1d8",
      "name": "Chuẩn hóa thông tin lead"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "list",
          "cachedResultName": "-- Chọn file của bạn --",
          "cachedResultUrl": ""
        },
        "sheetName": {
          "__rl": true,
          "value": "",
          "mode": "list",
          "cachedResultName": "-- Chọn trang tính CRM của bạn --",
          "cachedResultUrl": ""
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {
            "user_id": "={{ $json.user_id }}",
            "platform": "={{ $json.platform }}",
            "customer_name": "={{ $json.customer_name }}",
            "username": "=",
            "phone": "={{ $json.phone }}",
            "email": "={{ $json.email }}",
            "conversation_count": "1",
            "contact_method": "={{ $json.platform }}",
            "form_sent": "={{ $json.form_sent }}",
            "form_submitted": "={{ $json.form_submitted }}",
            "created_at": "={{ $json.created_at }}",
            "status": "={{ $json.status }}",
            "conversation_summary": "={{ $json.conversation_summary }}",
            "customer_need": "={{ $json.customer_need }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "user_id",
              "displayName": "user_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "platform",
              "displayName": "platform",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "customer_name",
              "displayName": "customer_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "username",
              "displayName": "username",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "phone",
              "displayName": "phone",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "displayName": "email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "conversation_count",
              "displayName": "conversation_count",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "lead_offer_shown",
              "displayName": "lead_offer_shown",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "lead_captured",
              "displayName": "lead_captured",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "intent_type",
              "displayName": "intent_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "contact_method",
              "displayName": "contact_method",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "form_sent",
              "displayName": "form_sent",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "form_submitted",
              "displayName": "form_submitted",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "office_visit_interest",
              "displayName": "office_visit_interest",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "last_message",
              "displayName": "last_message",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "last_bot_reply",
              "displayName": "last_bot_reply",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "last_interaction_at",
              "displayName": "last_interaction_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "created_at",
              "displayName": "created_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "updated_at",
              "displayName": "updated_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "source",
              "displayName": "source",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "note",
              "displayName": "note",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "customer_type",
              "displayName": "customer_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "conversation_summary",
              "displayName": "conversation_summary",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "customer_need",
              "displayName": "customer_need",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        -336,
        0
      ],
      "id": "dce7f734-bbe0-4cbd-9860-c273dd2c7e7f",
      "name": "Ghi vào Lead CRM Sheet"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "z1",
              "name": "admin_zalo_message",
              "value": "={{\n'🔥 LEAD MỚI TỪ LANDING PAGE\\n\\n' +\n'📚 Sản phẩm: [TÊN SẢN PHẨM / KHÓA HỌC]\\n' +\n'🆔 Mã lead: ' + ($json.user_id || '-') + '\\n' +\n'⏰ Thời gian: ' + ($json.created_at || '-') + '\\n' +\n'🌐 Nguồn: ' + ($json.platform || '-') + '\\n\\n' +\n'👤 THÔNG TIN KHÁCH\\n' +\n'• Tên: ' + ($json.customer_name || '-') + '\\n' +\n'• SĐT/Zalo: ' + ($json.phone || '-') + '\\n' +\n'• Email: ' + ($json.email || '-') + '\\n\\n' +\n'🎯 QUAN TÂM\\n' + ($json.customer_need || '-') + '\\n\\n' +\n'✅ Email cảm ơn đã gửi tự động. Việc cần làm: gọi lại trong khung giờ phù hợp, kiểm tra khách đã nhắn Messenger/Zalo chưa.'\n}}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -112,
        -144
      ],
      "id": "cc1114e4-3e42-46e7-b29f-609801f15bd7",
      "name": "Soạn tin báo admin"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://bot-api.zaloplatforms.com/botYOUR_BOT_TOKEN/sendMessage",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "chat_id",
              "value": "YOUR_CHAT_ID"
            },
            {
              "name": "text",
              "value": "={{ $json.admin_zalo_message }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        112,
        -144
      ],
      "id": "701d178e-6224-4f55-b6d5-93aa2f3e3e5e",
      "name": "Báo Zalo cho admin",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "jsCode": "// Sửa các dòng này cho đúng thương hiệu và sản phẩm của bạn.\nconst BRAND = '[TÊN THƯƠNG HIỆU]';\nconst SENDER = '[Tên người gửi]';\nconst PRODUCT = '[TÊN SẢN PHẨM / KHÓA HỌC]';\nconst PRODUCT_NOTE = '[Ví dụ: 6 buổi, học online]';\nconst PITCH = '[Một đoạn ngắn: sau khi học / dùng sản phẩm, khách làm được gì cụ thể]';\nconst MESSENGER = 'https://m.me/your-page';\nconst ZALO = 'https://zalo.me/0900000000';\nconst PHONE = '0900000000';\nconst LANDING = 'https://your-website.com/landing-page/';\nconst SITE = 'https://your-website.com';\nconst SUPPORT_EMAIL = 'you@example.com';\n\nconst c = items[0].json;\nconst name = (c.customer_name && c.customer_name !== 'Chưa cung cấp') ? c.customer_name : 'bạn';\nconst host = (u) => u.replace(/^https?:\\/\\//, '').replace(/\\/$/, '');\n\nconst html = `\n<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <link href=\"https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700&display=swap\" rel=\"stylesheet\">\n</head>\n<body style=\"margin:0;padding:0;background:#f3f4f6;font-family:'Be Vietnam Pro',Arial,sans-serif;color:#111827;\">\n  <div style=\"max-width:600px;margin:0 auto;padding:24px;\">\n\n    <div style=\"background:#0B1F3A;padding:28px 28px 24px;border-radius:14px 14px 0 0;\">\n      <div style=\"margin-bottom:16px;font-size:22px;font-weight:700;color:#ffffff;\">${BRAND}</div>\n      <h2 style=\"margin:0 0 6px;font-size:21px;font-weight:700;color:#ffffff;line-height:1.4;\">Cảm ơn ${name} đã quan tâm</h2>\n      <div style=\"font-size:13px;color:#8fafd4;\">${PRODUCT} · ${PRODUCT_NOTE}</div>\n    </div>\n\n    <div style=\"background:#ffffff;padding:26px 28px;border-left:1px solid #e5e7eb;border-right:1px solid #e5e7eb;\">\n      <p style=\"margin:0 0 16px;font-size:15px;line-height:1.75;\">Cảm ơn ${name} đã để lại thông tin và quan tâm đến <strong>${PRODUCT}</strong>.</p>\n      <p style=\"margin:0 0 16px;font-size:15px;line-height:1.75;\">${PITCH}</p>\n      <p style=\"margin:0 0 14px;font-size:15px;line-height:1.75;\">Cách nhanh nhất để được tư vấn là nhắn cho chúng tôi qua Messenger hoặc Zalo:</p>\n\n      <div style=\"text-align:center;margin:18px 0 10px;\">\n        <a href=\"${MESSENGER}\" style=\"display:inline-block;background:#35C2FF;color:#0B1F3A;text-decoration:none;font-weight:700;font-size:15px;padding:13px 26px;border-radius:8px;margin:4px;\">Nhắn Messenger</a>\n        <a href=\"${ZALO}\" style=\"display:inline-block;background:#ffffff;color:#0B1F3A;text-decoration:none;font-weight:700;font-size:15px;padding:12px 26px;border-radius:8px;border:1px solid #35C2FF;margin:4px;\">Nhắn Zalo</a>\n      </div>\n\n      <p style=\"margin:14px 0 0;font-size:14px;line-height:1.7;color:#4b5563;\">Chúng tôi sẽ gọi lại cho ${name} trong thời gian sớm nhất. Nếu cần gấp, có thể gọi trực tiếp: <strong style=\"color:#0B1F3A;\">${PHONE}</strong></p>\n      <p style=\"margin:10px 0 0;font-size:14px;line-height:1.7;color:#4b5563;\">Xem lại chi tiết: <a href=\"${LANDING}\" style=\"color:#123C73;\">${host(LANDING)}</a></p>\n    </div>\n\n    <div style=\"background:#f9fafb;border:1px solid #e5e7eb;border-top:0;padding:18px 28px;border-radius:0 0 14px 14px;\">\n      <p style=\"margin:0;font-size:13px;line-height:1.8;color:#6b7280;\">${SENDER} — ${BRAND}<br><a href=\"${SITE}\" style=\"color:#123C73;text-decoration:none;\">${host(SITE)}</a> · ${SUPPORT_EMAIL}</p>\n    </div>\n\n  </div>\n</body>\n</html>\n`;\n\nreturn [{ json: {\n  html,\n  email: c.email,\n  subject: 'Cảm ơn ' + name + ' đã quan tâm ' + PRODUCT + ' — ' + BRAND\n} }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -112,
        96
      ],
      "id": "0334297e-4ffc-4610-a056-120705b05551",
      "name": "Soạn email cảm ơn khách"
    },
    {
      "parameters": {
        "fromEmail": "you@example.com",
        "toEmail": "={{ $json.email }}",
        "subject": "={{ $json.subject }}",
        "html": "={{ $json.html }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        112,
        96
      ],
      "id": "b4e397df-ff99-4ade-8227-d50251aa9abc",
      "name": "Gửi email cho khách",
      "webhookId": "a5875ef2-d70c-41c2-b1cd-521c85d735d0",
      "onError": "continueRegularOutput"
    }
  ],
  "pinData": {},
  "connections": {
    "Lọc spam & validate": {
      "main": [
        [
          {
            "node": "Chuẩn hóa thông tin lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chuẩn hóa thông tin lead": {
      "main": [
        [
          {
            "node": "Ghi vào Lead CRM Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ghi vào Lead CRM Sheet": {
      "main": [
        [
          {
            "node": "Soạn tin báo admin",
            "type": "main",
            "index": 0
          },
          {
            "node": "Soạn email cảm ơn khách",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Soạn tin báo admin": {
      "main": [
        [
          {
            "node": "Báo Zalo cho admin",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Soạn email cảm ơn khách": {
      "main": [
        [
          {
            "node": "Gửi email cho khách",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook Landing page": {
      "main": [
        [
          {
            "node": "Lọc spam & validate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "nodeGroups": [],
  "tags": []
}