多通訊管道資料庫驅動的任務提醒系統 - n8n 工作流程

使用強大的 n8n 工作流、PostgreSQL、Slack、Telegram 和 Email 自動化多通訊管道的任務提醒。使用這個穩健的 n8n 範本來確保排程和傳送的可靠性。

工作流預覽

準備好自動化了嗎?

下載此 n8n 工作流程範本並立即開始使用。

適用對象

建置通知微服務的系統管理員和開發人員。
需要集中化、可設定提醒排程的團隊。
尋找用於多通訊管道溝通的穩健、複雜 n8n 範本的使用者。
任何需要使用 n8n 實作具備資料庫後援的韌性自動化解決方案的人。

總覽

這個穩健的自動化方案解決了建立可靠、多通訊管道任務通知系統的挑戰。透過利用 n8n 工作流,任務會透過專用的 Webhook 接收並安全地儲存在 PostgreSQL 資料庫中。此系統的關鍵部分是排程的 n8n 觸發器,它會定期檢查是否有到期的任務。其主要價值在於動態路由能力,允許使用者在建立任務時指定偏好的通訊管道——Email、Slack 或 Telegram。這種先進的 n8n 工作流架構確保關鍵任務提醒能可靠地送達最可能被看到的管道,使其成為任何 n8n 自動化集合中極具價值的補充。此範本展示了如何將 PostgreSQL n8n 節點用於資料管理和在 n8n 工作流中進行流程控制的最佳實踐。

運作方式

n8n 工作流結構上分為兩個主要元件:任務接收 (Task Ingestion) 和提醒派送 (Reminder Distribution)。


  1. 任務接收 (Webhook 觸發器): 當外部應用程式呼叫 Webhook - Receive Task n8n 觸發器並提交包含任務詳細資訊的 JSON 資料包時,流程開始。

  2. 驗證 (Validation): Validate Input n8n 節點強制執行約束條件,確保提供了 userId、taskName 和 reminderTime。此處失敗將立即導致 Error Response。

  3. 持久化 (Persistence): 驗證通過的任務會進入 Save Task to Database n8n 節點,並以 'pending' (待處理) 狀態儲存到 PostgreSQL 中。成功的操作會回傳 Success Response。

  4. 提醒派送 (排程觸發器): 此 n8n 工作流的第二部分由 Schedule Trigger - Every 5 Minutes n8n 觸發器啟動,它依據 cron 排程 (/5 *) 運行。

  5. 資料庫查詢 (Database Query): Fetch Due Tasks n8n 節點會查詢 PostgreSQL,找出 reminder_time 即將到期或已過期的待處理任務。

  6. 流程控制 (Flow Control): Check Tasks Exist n8n 節點確保只有在檢索到記錄時流程才會繼續。接著流程會使用 Split Into Items n8n 節點分割記錄,以便獨立處理每個任務。

  7. 管道路由 (Channel Routing): Route by Channel n8n 節點會根據 channel 欄位的值(email、slack 或 telegram)動態路由任務。

  8. 通知與傳送 (Notification & Delivery): 適當的通訊 n8n 節點(Send Email Reminder、Send Slack Reminder 或 Send Telegram Reminder)會傳送客製化的通知訊息。

  9. 完成 (Completion): 最後,Update Task Status n8n 節點會將 PostgreSQL 中的任務狀態更新為 'sent' (已傳送),從而在未來執行此強大 n8n 工作流時防止重複發送通知。

安裝指南

若要部署此完整的 n8n 工作流,請遵循以下步驟:


  1. 匯入 JSON: 複製提供的 n8n 工作流 JSON,並使用 'New' 選單 > 'Import from JSON' (從 JSON 匯入) 貼到您的 n8n 實例中。

  2. PostgreSQL 設定: 設定 Save Task to Database、Fetch Due Tasks 和 Update Task Status n8n 節點所使用的 PostgreSQL 憑證。請確保您的資料庫包含黏性提示 (sticky note) 中提供的 tasks 資料表結構。

  3. 通訊憑證設定: 為提醒傳送用的 n8n 節點設定憑證:

Email: 為 Send Email Reminder n8n 節點設定您的 SMTP 憑證。
Slack: 為 Send Slack Reminder n8n 節點設定您的 Slack API 憑證。
* Telegram: 為 Send Telegram Reminder n8n 節點設定您的 Telegram API 憑證。

  1. 啟用 Webhook: 從 Webhook - Receive Task n8n 觸發器複製 Webhook URL,並將其整合到您的任務建立系統中。

  2. 啟用: 確保 n8n 工作流標記為 'Active' (啟用中),以便排程觸發器開始運行。

節點詳情

此 n8n 工作流使用數個關鍵的 n8n 節點來實現穩健的功能:

Webhook - Receive Task (n8n 觸發器): 主要進入點。它監聽特定路徑 (task-YOUROPENAIKEYHERE-webhook) 以接收新的任務建立請求。
Postgres 節點 (Save Task to Database): 儲存已驗證的任務資料。關鍵設定包括將操作設定為 'Insert' (插入) 並指定目標資料表(暗示為 tasks 資料表)。
Schedule Trigger - Every 5 Minutes (n8n 觸發器): 使用 cron 表達式 /5 定期啟動提醒檢查程序。
Postgres 節點 (Fetch Due Tasks): 執行自訂 SQL 查詢(SELECT FROM tasks WHERE status = 'pending' AND reminder
time <= NOW() + INTERVAL '5 minutes' AND remindertime > NOW())以檢索相關記錄。
If 節點 (Validate Input & Check Tasks Exist): 對於流程控制至關重要。驗證節點檢查關鍵輸入是否為空。存在性檢查則驗證資料庫是否返回了任何項目。
Switch 節點 (Route by Channel): 根據任務的 channel 欄位決定提醒傳送路徑,將 n8n 流程連接到 Email (輸出 0)、Slack (輸出 1) 或 Telegram (輸出 2)。
Email Send 節點 (Send Email Reminder): 設定為向 userid 發送個人化的主旨行(⏰ Task Reminder: {{ $json.taskname }})和內文。
Slack 節點 (Send Slack Reminder): 發送格式化的 Markdown 訊息,透過從資料庫項目檢索到的 user
id 向使用者動態尋址。
Telegram 節點 (Send Telegram Reminder): 使用 Markdown 格式向目標 chatId({{ $json.userid }})發送訊息。
Postgres 節點 (Update Task Status): 執行 UPDATE 查詢,將 status 設定為 'sent',sent
at 設定為 NOW(),從而完成此強大 n8n 節點實作的整個流程。

相關 n8n 工作流程

免費

節點: 11 節點
更新时间: 2025年12月26日
建立者

The AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.

精選*