Authorization
憑證)。POST
dify-test
When Last Node Finishes
(確保 AI 回覆後才回傳)First Incoming Item
http://localhost:5678/webhook-test/dify-test
)
POST
https://api.dify.ai/v1/chat-messages
Content-Type
= application/json
Authorization
= Bearer 你的Dify API金鑰
(替換成 Part 1 複製的金鑰)JSON
{
"inputs": {},
"query": "={{$json["message"]}}",
"response_mode": "blocking",
"user": "api-user"
}
"={{$json["message"]}}"
是 n8n 的表達式,用於動態擷取 Webhook 傳入的 JSON 數據中的 message
欄位。JSON
{
"reply": "={{$json["answer"] || $json["outputs"][0]["content"] || $json["data"]}}"
}
First Incoming Item
(會把 Set 節點輸出的 JSON {"reply":"..."}
回傳給呼叫者)。啟用 Workflow 後,使用 PowerShell 執行 POST 請求,將帶有中文的 JSON ({"message": "今天天氣怎樣"}
) 傳給 Webhook。
Invoke-RestMethod -Uri "http://localhost:5678/webhook-test/dify-test" `
-Method POST `
-Headers @{ "Content-Type" = "application/json; charset=utf-8" } `
-Body (@{ message = "今天天氣怎樣" } | ConvertTo-Json -Depth 3 -Compress)
先暫時更新,最後會補圖。