開啟 n8n → 點擊 Create Workflow
拖入 Cron Node(排程觸發):
拖一個 Function Node,內容輸入以下程式碼:
const messages = [
{ type: "drink", text: "📢 每日提醒:記得喝水 💧" },
{ type: "stretch", text: "📢 每日提醒:起來伸展一下 🧘" },
{ type: "focus", text: "📢 每日提醒:保持專注 🔥" }
];
const randomMsg = messages[Math.floor(Math.random() * messages.length)];
return [{
json: {
subject: "每日提醒",
type: randomMsg.type,
text: randomMsg.text
}
}];
這樣每次執行都會隨機產生不同提醒,並附帶一個 type 標籤(例如 "drink"
/ "stretch"
/ "focus"
)。
拖入一個 If Node
設定條件:
{{$json["type"]}}
equals
drink
在 If Node 的 True output 接一個 Email Node。
設定:
={{$json["subject"]}}
={{$json["text"]}} (這是喝水提醒 💧)
在 If Node 的 False output 接另一個 Email Node。
設定:
={{$json["subject"]}}
={{$json["text"]}} (這是非喝水提醒 🚀)