{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "915497a7-0013-4783-8dff-13d955df32a3",
      "name": "Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        224
      ],
      "parameters": {
        "width": 540,
        "height": 688,
        "content": "## \ud83c\udfe0 LINE AI Real Estate Assistant\n\nThis workflow creates an intelligent real estate assistant that automatically responds to customer inquiries via LINE Bot, powered by Google Gemini AI.\n\n### How it works\n1. LINE Webhook receives customer messages\n2. Message Parser extracts key info (budget, rooms, area)\n3. Google Gemini AI generates personalized responses\n4. All inquiries logged to Google Sheets\n5. High-value leads trigger email alerts to sales team\n6. AI response sent back to customer via LINE\n\n### Setup steps\n1. Create LINE Messaging API channel and get Channel Access Token\n2. Configure Google Gemini API credentials\n3. Set up Google Sheets for inquiry logging\n4. Configure SMTP for sales alert emails\n5. Set webhook URL in LINE Developer Console\n\n### Key features\n- \ud83e\udd16 AI-powered Japanese real estate expertise\n- \ud83d\udccb Automatic inquiry classification (rental/purchase/viewing)\n- \ud83d\udc8e High-value lead detection and sales alerts\n- \ud83d\udcca Complete interaction logging to Google Sheets\n- \ud83d\udd04 Automatic LINE reply with AI response\n- \ud83d\udce7 Email notifications for premium prospects\n\n\u26a0\ufe0f Note: Requires LINE Messaging API, Google Gemini, Google Sheets, and SMTP credentials."
      },
      "typeVersion": 1
    },
    {
      "id": "89108961-a2de-4d8d-9aad-785deabf25e2",
      "name": "Step 1 - Reception & Parsing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        432,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 588,
        "height": 380,
        "content": "### Step 1 - Message Reception & Parsing\nLINE Webhook receives customer messages. Parser extracts budget, rooms, area, and classifies inquiry type (rental/purchase/viewing).\n\n**Setup:** LINE Channel Access Token + Webhook URL"
      },
      "typeVersion": 1
    },
    {
      "id": "2e261384-3dcf-45cc-aa8c-33a2387b2def",
      "name": "Step 2 - AI Analysis",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1040,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 420,
        "height": 536,
        "content": "### Step 2 - AI Property Advisor\nGoogle Gemini AI generates professional Japanese real estate responses. Personalized advice based on extracted budget, room, and area preferences.\n\n**Model:** Gemini 1.5 Flash\n**Language:** Japanese (\u656c\u8a9e)\n**Limit:** 200 chars for LINE"
      },
      "typeVersion": 1
    },
    {
      "id": "84b68aa7-453a-4222-9a98-1c0c909f15e0",
      "name": "Step 3 - Logging & Routing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1488,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 588,
        "height": 616,
        "content": "### Step 3 - Logging & Lead Detection\nAll inquiries saved to Google Sheets. High-value leads (purchase intent or budget >\u00a530M) trigger email alerts to sales team.\n\n**Sheets:** Full interaction log\n**Filter:** Purchase OR budget >3000\u4e07\u5186"
      },
      "typeVersion": 1
    },
    {
      "id": "361dcba5-9cdc-4da7-98c7-626129de4b02",
      "name": "Step 4 - Reply & Alerts",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2096,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 588,
        "height": 616,
        "content": "### Step 4 - Reply & Notifications\nFormatted AI response sent back to customer via LINE API. Sales team receives email alerts for high-value inquiries.\n\n**LINE Reply:** Auto-response with AI advice\n**Email Alert:** High-value lead notification"
      },
      "typeVersion": 1
    },
    {
      "id": "5d676ec2-b434-4acb-99fc-1595f5d2c1b0",
      "name": "LINE Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        464,
        432
      ],
      "parameters": {
        "path": "line-realestate-webhook",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "d6d72938-f7ce-4949-9255-a5391f3fcb91",
      "name": "Parse LINE Message",
      "type": "n8n-nodes-base.code",
      "position": [
        752,
        432
      ],
      "parameters": {
        "jsCode": "// Extract LINE message data and classify inquiry\nconst body = $input.first().json.body;\nconst events = body.events || [];\n\nif (events.length === 0) {\n  return [{ json: { skip: true } }];\n}\n\nconst event = events[0];\nconst userMessage = event.message?.text || '';\nconst userId = event.source?.userId || '';\nconst replyToken = event.replyToken || '';\n\n// Classify inquiry type\nlet inquiryType = 'general';\nif (userMessage.includes('\u8cc3\u8cb8') || userMessage.includes('\u5bb6\u8cc3')) inquiryType = 'rental';\nelse if (userMessage.includes('\u58f2\u8cb7') || userMessage.includes('\u8cfc\u5165') || userMessage.includes('\u8cb7\u3044')) inquiryType = 'purchase';\nelse if (userMessage.includes('\u5185\u898b') || userMessage.includes('\u898b\u5b66')) inquiryType = 'viewing';\n\n// Extract key info with Japanese regex\nconst budgetMatch = userMessage.match(/(\\d+)\u4e07/);\nconst roomsMatch = userMessage.match(/(\\d+)[LDK]/);\nconst areaMatch = userMessage.match(/([\\u3040-\\u309f\\u4e00-\\u9faf]+[\u533a\u5e02\u753a\u6751])/);\n\nreturn [{\n  json: {\n    userId,\n    replyToken,\n    userMessage,\n    inquiryType,\n    budget: budgetMatch ? parseInt(budgetMatch[1]) : null,\n    rooms: roomsMatch ? roomsMatch[0] : null,\n    area: areaMatch ? areaMatch[1] : null,\n    timestamp: new Date().toISOString()\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "598a5ce6-177d-49d8-9d75-1eeeda4018b0",
      "name": "AI Property Advisor",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1104,
        432
      ],
      "parameters": {
        "text": "=\u3042\u306a\u305f\u306f\u4e0d\u52d5\u7523\u4f1a\u793e\u306e\u30d7\u30ed\u30d5\u30a7\u30c3\u30b7\u30e7\u30ca\u30eb\u306aLINE\u30a2\u30b7\u30b9\u30bf\u30f3\u30c8\u3067\u3059\u3002\n\n\u9867\u5ba2\u30e1\u30c3\u30bb\u30fc\u30b8: {{ $json.userMessage }}\n\u554f\u3044\u5408\u308f\u305b\u7a2e\u985e: {{ $json.inquiryType }}\n\u4e88\u7b97: {{ $json.budget ? $json.budget + '\u4e07\u5186' : '\u672a\u6307\u5b9a' }}\n\u9593\u53d6\u308a: {{ $json.rooms || '\u672a\u6307\u5b9a' }}\n\u30a8\u30ea\u30a2: {{ $json.area || '\u672a\u6307\u5b9a' }}\n\n\u4ee5\u4e0b\u306e\u30eb\u30fc\u30eb\u3067\u8fd4\u7b54\u3057\u3066\u304f\u3060\u3055\u3044:\n1. \u656c\u8a9e\u3067\u89aa\u3057\u307f\u3084\u3059\u304f\n2. \u5177\u4f53\u7684\u306a\u63d0\u6848\u3092\u3059\u308b\n3. \u4e0d\u8db3\u60c5\u5831\u306f\u81ea\u7136\u306b\u8cea\u554f\n4. \u5185\u898b\u3084\u76f8\u8ac7\u3078\u306e\u8a98\u5c0e\n5. 200\u6587\u5b57\u4ee5\u5185\n\n\u5f62\u5f0f:\n\ud83c\udfe0 [\u6328\u62f6]\n[\u56de\u7b54\u30fb\u63d0\u6848]\n[\u6b21\u306e\u30b9\u30c6\u30c3\u30d7]\n\ud83d\udcde\u304a\u6c17\u8efd\u306b\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\uff01",
        "promptType": "define"
      },
      "typeVersion": 1.4
    },
    {
      "id": "90a507d3-a09a-48fc-9579-bd80793446c4",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1104,
        608
      ],
      "parameters": {
        "options": {
          "temperature": 0.3
        },
        "modelName": "models/gemini-1.5-flash"
      },
      "typeVersion": 1
    },
    {
      "id": "7ee0df10-51f2-488d-89a3-3822d0c84c68",
      "name": "Process AI Response",
      "type": "n8n-nodes-base.code",
      "position": [
        1520,
        432
      ],
      "parameters": {
        "jsCode": "// Parse AI response and prepare data for logging and reply\nconst aiResponse = $input.first().json.text || $input.first().json.response || '';\nconst prevData = $('Parse LINE Message').first().json;\n\nreturn [{\n  json: {\n    ...prevData,\n    aiResponse,\n    isHighValue: prevData.inquiryType === 'purchase' || (prevData.budget && prevData.budget > 3000)\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "5a65e3b9-bbe5-4118-bd7c-adbb8391c5d5",
      "name": "Log to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1808,
        432
      ],
      "parameters": {
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "66352073-d0b8-4d0f-9d83-5b55646f66f8",
      "name": "High-Value Lead Check",
      "type": "n8n-nodes-base.if",
      "position": [
        1808,
        688
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "high-value-check",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.isHighValue }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "dcc95255-e221-406c-9f2f-415355a979a8",
      "name": "Send LINE Reply",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2128,
        432
      ],
      "parameters": {
        "url": "https://api.line.me/v2/bot/message/reply",
        "method": "POST",
        "options": {},
        "jsonBody": "={ \"replyToken\": \"{{ $json.replyToken }}\", \"messages\": [{ \"type\": \"text\", \"text\": \"{{ $json.aiResponse }}\" }] }",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "=Bearer YOUR_LINE_CHANNEL_ACCESS_TOKEN"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "87d5a2cb-c50d-4bcc-9485-a24d7b8145c6",
      "name": "Send Sales Alert",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        2128,
        688
      ],
      "parameters": {
        "options": {},
        "subject": "=\ud83c\udfe0 \u9ad8\u984d\u6848\u4ef6\u30a2\u30e9\u30fc\u30c8: {{ $json.inquiryType }} - {{ $json.area || '\u30a8\u30ea\u30a2\u672a\u6307\u5b9a' }}",
        "toEmail": "user@example.com",
        "fromEmail": "user@example.com"
      },
      "typeVersion": 2.1
    }
  ],
  "connections": {
    "LINE Webhook": {
      "main": [
        [
          {
            "node": "Parse LINE Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse LINE Message": {
      "main": [
        [
          {
            "node": "AI Property Advisor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Property Advisor": {
      "main": [
        [
          {
            "node": "Process AI Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process AI Response": {
      "main": [
        [
          {
            "node": "Log to Google Sheets",
            "type": "main",
            "index": 0
          },
          {
            "node": "High-Value Lead Check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Google Sheets": {
      "main": [
        [
          {
            "node": "Send LINE Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "High-Value Lead Check": {
      "main": [
        [
          {
            "node": "Send Sales Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Property Advisor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}