{
  "name": "Blossom｜LINE AI 外燴客服 MVP｜OpenCode Go + DeepSeek V4 Flash",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "line-ai-customer-service",
        "options": {}
      },
      "id": "fce7296a-08b1-43c6-9631-85d3230ef407",
      "name": "LINE｜Blossom AI 客服",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        368
      ],
      "webhookId": "line-ai-customer-service"
    },
    {
      "parameters": {
        "jsCode": "const body = $json.body ?? $json;\nconst event = body.events?.[0] ?? {};\nconst text = event.message?.text ?? '';\nconst replyToken = event.replyToken ?? '';\nconst source = event.source?.userId ?? '';\nconst destination = body.destination ?? '';\nconst channel = 'ai-customer-service';\n\nconst SHEET_ID = 'REPLACE_BLOSSOM_KNOWLEDGE_SHEET_ID';\nconst GID = 'REPLACE_BLOSSOM_KNOWLEDGE_GID';\n\nconst csv = await this.helpers.httpRequest({\n  method: 'GET',\n  url: `https://docs.google.com/spreadsheets/d/${SHEET_ID}/export?format=csv&gid=${GID}`\n});\n\nconst rows = String(csv).trim().split(/\\r?\\n/);\nconst query = text.toLowerCase();\nconst matched = rows.slice(1)\n  .filter(row => row.toLowerCase().includes(query))\n  .slice(0, 8);\n\nconst sheetKnowledge = [\n  rows[0],\n  ...(matched.length ? matched : rows.slice(1, 8))\n].join('\\n');\n\nconst knowledge = `【Blossom 外燴 AI 客服】\n角色：你是 Blossom 外燴客服助理，使用繁體中文，回答簡潔、清楚。\n\n主要任務：\n1. 協助客戶整理外燴需求。\n2. 回答知識庫中已有的服務資訊。\n3. 資料不足時，先補問必要資訊，不自行猜測。\n4. 正式報價、付款、退款、重大客訴與特殊承諾，轉人工確認。\n\n外燴詢價常用必要資訊：\n- 活動日期\n- 活動地點\n- 預計人數\n- 每人預算或總預算\n- 活動類型\n- 素食／過敏／其他特殊飲食需求\n- 若涉及配送或現場服務，再確認送達時間與服務需求\n\n回答規則：\n- 只能使用本知識庫與這次提供的 Sheet 資料。\n- 不捏造價格、菜色、空檔、付款條件、到場時間或已確認狀態。\n- 查不到資料時，明確說需要人工確認。\n- 正式報價只能先整理需求與提供參考，不可假裝已成立報價。\n- 不要求或重述完整信用卡號、密碼、驗證碼、API Key、Token 等敏感資料。\n\n【Google Sheet 知識資料】\n${sheetKnowledge}\n\n回答時先回答客戶目前的問題；若資訊不足，再只補問下一步真正需要的資訊。`;\n\nreturn [{\n  json: {\n    channel,\n    text,\n    replyToken,\n    source,\n    destination,\n    knowledge\n  }\n}];"
      },
      "id": "2c909e56-1a67-44f3-a495-63ffb4e57c8d",
      "name": "共用知識庫｜先取資料",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        352,
        192
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://opencode.ai/zen/go/v1/chat/completions",
        "authentication": "genericCredentialType",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { model: 'deepseek-v4-flash', messages: [ { role: 'system', content: '你是 Blossom 外燴 AI 客服。只能依據提供的知識庫回答；不可捏造資料。知識庫沒有答案就說需要人工確認。使用繁體中文，簡潔、可執行。' }, { role: 'user', content: '知識庫：' + $json.knowledge + '\\n\\n使用者訊息：' + $json.text } ], temperature: 0.2, max_tokens: 512 } }}",
        "options": {
          "timeout": 30000
        },
        "genericAuthType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-opencode-session",
              "value": "={{ 'blossom-line-' + $json.source }}"
            },
            {
              "name": "User-Agent",
              "value": "blossom-line-agent/1.0"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "id": "5114d50d-1cdc-41af-8730-b23117722d0c",
      "name": "AI大腦｜OpenCode Go DeepSeek V4 Flash",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        720,
        192
      ],
      "retryOnFail": true,
      "onError": "continueRegularOutput",
      "maxTries": 3,
      "waitBetweenTries": 1000
    },
    {
      "parameters": {
        "jsCode": "const original = $node['共用知識庫｜先取資料'].json;\nconst answer = $json.candidates?.[0]?.content?.parts?.map(p => p.text || '').join('') || $json.choices?.[0]?.message?.content || '目前 AI 客服忙碌中，請稍後再試或留言由真人協助。';\nreturn [{json:{...original, answer}}];"
      },
      "id": "f52b5fe6-b092-491e-9de3-3b4af3b4ad1c",
      "name": "整理 LINE 回覆",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1088,
        192
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.line.me/v2/bot/message/reply",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{JSON.stringify({replyToken:$json.replyToken,messages:[{type:'text',text:$json.answer.slice(0,4900)}]})}}",
        "options": {
          "timeout": 15000
        },
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth"
      },
      "id": "e5d32649-7af8-45d7-9208-8752557ad5c5",
      "name": "LINE 回覆使用者",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1440,
        192
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "REPLACE_BLOSSOM_LOG_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "REPLACE_BLOSSOM_LOG_SHEET_GID",
          "mode": "id"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "時間": "={{$now.toISO()}}",
            "使用者": "={{$json.source}}",
            "分類": "={{($json.text || \"店務回報\").split(/\\s+/)[0]}}",
            "內容": "={{$json.text}}",
            "狀態": "={{\"待處理\"}}",
            "來源": "={{$json.channel}}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "時間",
              "displayName": "時間",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "來源",
              "displayName": "來源",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "使用者",
              "displayName": "使用者",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "分類",
              "displayName": "分類",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "內容",
              "displayName": "內容",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "狀態",
              "displayName": "狀態",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        560,
        192
      ],
      "id": "af5d7d10-6ecd-4776-ae44-bcd67c33fa01",
      "name": "Append row in sheet"
    }
  ],
  "connections": {
    "LINE｜Blossom AI 客服": {
      "main": [
        [
          {
            "node": "共用知識庫｜先取資料",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "共用知識庫｜先取資料": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          },
          {
            "node": "AI大腦｜OpenCode Go DeepSeek V4 Flash",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "整理 LINE 回覆": {
      "main": [
        [
          {
            "node": "LINE 回覆使用者",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LINE 回覆使用者": {
      "main": [
        []
      ]
    },
    "AI大腦｜OpenCode Go DeepSeek V4 Flash": {
      "main": [
        [
          {
            "node": "整理 LINE 回覆",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}