先到 Google 試算表 建立一份新的表格。
命名為:AI 對話紀錄
在第一列建立標題欄:
Timestamp | User | Message | AI Reply |
---|
GoogleSheet_Auth
。Webhook → Function(解析訊息)→ HTTP Request(Dify)→ Function(整理紀錄)→ Google Sheet(Append Row)→ HTTP Request(回傳 LINE)
在 Dify 回覆後,新增一個 Function 節點,放在「Dify → Google Sheet」之間,
把 webhook 傳進來的使用者訊息、AI 回覆、時間都整理好。
return [{
json: {
Timestamp: new Date().toLocaleString('zh-TW', { timeZone: 'Asia/Taipei' }),
User: "LINE",
Message: $json["user_message"],
AI_Reply: $json["answer"]
}
}];
1️⃣ 新增一個節點:Google Sheets → Append Sheet Row
2️⃣ 選擇剛剛建立的憑證(GoogleSheet_Auth
)
3️⃣ 在設定中選擇你剛才的試算表與工作表名稱
4️⃣ 開啟「Use field names as headers」
(n8n 會自動把 Function 節點裡的 Timestamp
, User
, Message
, AI_Reply
對應進欄位)
執行後,n8n 就會自動在 Google Sheet 最下方新增一筆紀錄 👇
Timestamp | User | Message | AI Reply |
---|---|---|---|
2025/10/07 23:15 | LINE | 今天天氣怎樣 | 今天台北多雲偶陣雨,氣溫介於26到30度之間。 |
[LINE 使用者]
↓
Webhook (n8n)
↓
Function(解析 message、replyToken)
↓
HTTP Request(呼叫 Dify 產生回覆)
↓
Function(整理資料)
↓
Google Sheet(Append Row)
↓
HTTP Request(回傳訊息給 LINE)