{
  "name": "LabelMaster — LINE OA chat → Google Sheets log (BASIC)",
  "nodes": [
    {
      "parameters": {
        "content": "## LabelMaster · LINE OA → Google Sheets (BASIC)\n\n**ทำอะไร:** ลูกค้าทักเข้า LINE OA → ระบบเก็บข้อความลง Google Sheets อัตโนมัติ (กรองเฉพาะข้อความ text)\n\n**ก่อน Activate ต้องแก้ 3 จุด (ดู Sticky สีเหลือง):**\n1. Google Sheet ID ที่ node 'Append row'\n2. เชื่อม Google credential\n3. เอา Production Webhook URL ไปวางใน LINE Developers Console\n\nสร้างโดยทีม AICE · Make/n8n · งานช่างฝีมือ ไม่รีบ",
        "height": 300,
        "width": 360
      },
      "id": "note-overview",
      "name": "อ่านก่อน — ภาพรวม",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-120, 40]
    },
    {
      "parameters": {
        "content": "### ⚠️ แก้ 3 จุดนี้ก่อนใช้งานจริง\n\n• **Google Sheet ID** → node \"Google Sheets — Append row\" ช่อง Document\n• **Credential** → เชื่อมบัญชี Google ของคุณเก่ง\n• **LINE Webhook URL** → คัดลอก Production URL จาก node \"LINE Webhook\" ไปวางใน LINE Developers → Messaging API → Webhook URL แล้วเปิด \"Use webhook\" + ปิด auto-reply",
        "height": 260,
        "width": 340
      },
      "id": "note-todo",
      "name": "3 จุดที่ต้องแก้",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [820, -220]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "labelmaster-line-inbound",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-line",
      "name": "LINE Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [120, 300],
      "webhookId": "labelmaster-line-inbound"
    },
    {
      "parameters": {
        "respondWith": "text",
        "responseBody": "OK",
        "options": {}
      },
      "id": "respond-200",
      "name": "ตอบ 200 ให้ LINE (ทันที)",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [360, 160]
    },
    {
      "parameters": {
        "fieldToSplitOut": "body.events",
        "options": {}
      },
      "id": "split-events",
      "name": "แยกแต่ละ event",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [360, 420]
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "typeValidation": "strict", "version": 2 },
          "conditions": [
            {
              "id": "cond-text",
              "leftValue": "={{ $json.message.type }}",
              "rightValue": "text",
              "operator": { "type": "string", "operation": "equals" }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "if-text",
      "name": "เฉพาะข้อความ (กรองสติกเกอร์/รูป)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [580, 420]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a-time",
              "name": "เวลา",
              "value": "={{ $now.setZone('Asia/Bangkok').toFormat('dd/MM/') + ($now.setZone('Asia/Bangkok').year + 543) + ' ' + $now.setZone('Asia/Bangkok').toFormat('HH:mm') }}",
              "type": "string"
            },
            {
              "id": "a-uid",
              "name": "User ID",
              "value": "={{ $json.source.userId }}",
              "type": "string"
            },
            {
              "id": "a-text",
              "name": "ข้อความ",
              "value": "={{ $json.message.text }}",
              "type": "string"
            },
            {
              "id": "a-status",
              "name": "สถานะ",
              "value": "ใหม่",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "normalize",
      "name": "จัดรูปข้อมูล (วันที่ พ.ศ. + สถานะ)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [800, 360]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": { "__rl": true, "value": "<<ใส่_GOOGLE_SHEET_ID_ที่นี่>>", "mode": "id" },
        "sheetName": { "__rl": true, "value": "leads_log", "mode": "name" },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "เวลา": "={{ $json['เวลา'] }}",
            "User ID": "={{ $json['User ID'] }}",
            "ข้อความ": "={{ $json['ข้อความ'] }}",
            "สถานะ": "={{ $json['สถานะ'] }}"
          },
          "matchingColumns": []
        },
        "options": {}
      },
      "id": "sheets-append",
      "name": "Google Sheets — Append row",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [1020, 360],
      "credentials": {
        "googleSheetsOAuth2Api": { "id": "REPLACE_CREDENTIAL_ID", "name": "Google Sheets (LabelMaster)" }
      }
    }
  ],
  "connections": {
    "LINE Webhook": {
      "main": [[
        { "node": "ตอบ 200 ให้ LINE (ทันที)", "type": "main", "index": 0 },
        { "node": "แยกแต่ละ event", "type": "main", "index": 0 }
      ]]
    },
    "แยกแต่ละ event": {
      "main": [[ { "node": "เฉพาะข้อความ (กรองสติกเกอร์/รูป)", "type": "main", "index": 0 } ]]
    },
    "เฉพาะข้อความ (กรองสติกเกอร์/รูป)": {
      "main": [
        [ { "node": "จัดรูปข้อมูล (วันที่ พ.ศ. + สถานะ)", "type": "main", "index": 0 } ],
        []
      ]
    },
    "จัดรูปข้อมูล (วันที่ พ.ศ. + สถานะ)": {
      "main": [[ { "node": "Google Sheets — Append row", "type": "main", "index": 0 } ]]
    }
  },
  "settings": { "executionOrder": "v1" },
  "active": false,
  "pinData": {}
}
