iT邦幫忙

2025 iThome 鐵人賽

DAY 29
0
DevOps

n8n x AI自動化之新手村系列 第 29

Day29 每日任務清單生成

  • 分享至 

  • xImage
  •  

今天要做的是每日待辦生成,每天固定時間生成每日任務(固定任務),並自動抓取當天待辦事項,最後將兩者整合成簡潔清單並推送到 Telegram。這樣使用者一早就能清楚掌握每日工作與學習安排,幫助使用者能一目了然每日任務,提升效率與自律性。

實作流程

https://ithelp.ithome.com.tw/upload/images/20250908/20168759H3qTXOrvcz.png
每日固定任務(黃色)

  1. 建立code節點來生成固定的任務
    https://ithelp.ithome.com.tw/upload/images/20250908/20168759gFO0ZGfA8P.png
  2. 建立Notion節點,功能為create database page
    1. 設定database並將對應欄位設定好

讀取當天所有的行程(藍色)

  1. 建立Date&Time節點,取得當天日期

  2. 建立code節點,整理日期格式
    https://ithelp.ithome.com.tw/upload/images/20250908/20168759PGAgmNdYUM.jpg

  3. 建立Notion節點,功能為get database page

    1. 添加filter,將日期為當天的都取出(使用前一節點取得的日期作為比較依據)
      https://ithelp.ithome.com.tw/upload/images/20250908/20168759a0h03GzwOX.png

傳送到telegram(紫色)

  1. 建立code節點來編輯訊息

    // 假設 items 是 Notion Search Node 的輸出
    const notionItems = items || [];
    
    // 初始化陣列
    let fixedTasks = [];
    let todoTasks = [];
    
    // 遍歷 Notion 任務,依任務類型分類
    notionItems.forEach(it => {
      const taskName = it.json.properties['任務'].title?.[0]?.text?.content || "未命名任務";
      const taskDesc = it.json.properties['任務描述'].rich_text?.[0]?.text?.content || "未輸入任務內容";
      const taskType = it.json.properties['任務類型'].select?.name || "未分類";
    
      const fullTask = taskDesc ? `${taskName} — ${taskDesc}` : taskName;
    
      if (taskType === "固定任務") {
        fixedTasks.push(fullTask);
      } else if (taskType === "待辦事項") {
        todoTasks.push(fullTask);
      }
    });
    
    // ====== 組合 Telegram 訊息 ======
    let message = "";
    
    // 固定任務
    if (fixedTasks.length > 0) {
      message += "🏃 每日固定任務\n";
      fixedTasks.forEach((task, idx) => {
        message += `${idx + 1}. ${task}\n`;
      });
    } else {
      message += "🏃 今天沒有每日固定任務 🎉\n";
    }
    
    // 待辦事項
    message += "\n";
    if (todoTasks.length > 0) {
      message += "📝 今日待辦事項\n";
      todoTasks.forEach((task, idx) => {
        message += `${idx + 1}. ${task}\n`;
      });
    } else {
      message += "📝 今天沒有待辦事項 🎉\n";
    }
    
    // ====== 回傳給 Telegram Node ======
    return [{ json: { message } }];
    
  2. 建立telegram節點

    1. 新建bot
    2. 取得access token與chat id
    3. 設定要傳送的內容

成果

  • Notion (9/8為例)
    • 有五筆的每日固定任務與兩項的待辦事項
      https://ithelp.ithome.com.tw/upload/images/20250908/20168759Tjy6i1ogHr.jpg
  • telegram
    https://ithelp.ithome.com.tw/upload/images/20250908/20168759eukVrfb5cZ.png

經過這次的實作也讓我對n8n節點之間資訊的流動與運用有了更深的了解。


上一篇
Day28 Apify 爬蟲 -google map
系列文
n8n x AI自動化之新手村29
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言