LINE Bot 模擬助手
) → 按下建立在左側選單中點擊「提示詞 (Prompt)」
在系統提示中輸入 AI 的角色設定,例如:
你是一個友善的 LINE 聊天機器人,會以自然、親切的方式回答問題。
按右上角「儲存」
點左側「訪問 API (API Access)」
點右上角 「建立 API 金鑰」 → 複製該金鑰(稍後要貼進 n8n)
例:
Bearer dify-xxxxxxxxxxxxxxxx
這個流程的邏輯是:
「模擬 LINE 傳訊息」→ Webhook 接收 → 呼叫 Dify → 抽取回覆 → 回傳結果。
項目 | 設定值 |
---|---|
HTTP Method | POST |
Path | line-simulate |
Authentication | None |
Respond | Using “Respond to Webhook” Node |
Response Data | First Entry JSON |
測試網址:
http://localhost:5678/webhook-test/line-simulate
項目 | 值 |
---|---|
Method | POST |
URL | https://api.dify.ai/v1/chat-messages |
Authentication | None |
Headers | Authorization: Bearer <你的金鑰> 、Content-Type: application/json |
Body Content Type | JSON |
JSON Body |
{
"inputs": {},
"query": "={{$json['body']['message']}}",
"response_mode": "blocking",
"user": "line-sim-user"
}
新增 Set 節點
Mode 選 JSON
點「Add Field」 → 輸入:
reply
={{$json["answer"]}}
這樣它就只會保留 AI 回覆內容。
項目 | 值 |
---|---|
Respond With | First Incoming Item |
這樣整個回覆會回傳成 JSON 格式,例如:
{
"reply": "今天天氣很好喔 "
}
$json = '{"message":"你好,我想知道今天天氣"}'
Invoke-RestMethod -Uri "http://localhost:5678/webhook-test/line-simulate" `
-Method POST `
-Headers @{ "Content-Type" = "application/json; charset=utf-8" } `
-Body ([System.Text.Encoding]::UTF8.GetBytes($json))
在 PowerShell 中會回傳:
{
"reply": "你好~目前是晴朗的天氣,很適合出門走走。"
}