# **Google Tasks 串到 LINE Notify** 功能:會撈出存在Tasks的當天任務標題與內容內的meet會議室連結 在Google Apps Script 使用 Google Tasks 服務,要先啟用Tasks API。請按照以下步驟進行操作: 1. 在 Google Apps Script 編輯器中,點擊左上角的 "資源"(Resources)菜單。 2. 選擇 "進階 Google 服務"(Advanced Google services)。 3. 在彈出的對話框中,找到 "Tasks API" 並將其啟用。 4. 再貼上以下程式,改成您的 LINE Notify Access Token 5. 設定觸發條件即可 ![image](https://hackmd.io/_uploads/SyrdvRcJA.png) ``` function importTodayMeetLinksToLine() { var today = new Date(); var tasks = Tasks.Tasks.list('@default').items; // 获取 Google Tasks 列表 var lineAccessToken = 'LINE Notify 存取權杖改這邊'; // 您的 LINE Notify 存取權杖 var messageNumber = 1; for (var i = 0; i < tasks.length; i++) { var task = tasks[i]; var taskDue = new Date(task.due); // 取得任務的截止日期 var taskTitle = task.title; // 取得任務的標題 var taskNotes = task.notes; // 取得任務的描述 // 檢查任務描述中是否包含 MEET 連結且截止日期為今天 if (taskNotes && taskNotes.includes("http") && isSameDate(today, taskDue)) { var meetLinks = getMeetLinks(taskNotes); // 取得描述中的 MEET 連結 // var message = taskTitle + "\n" + meetLinks; // 將標題和 MEET 連結合併為一個字串 var message = (messageNumber) + "\n" + "任務標題:" + taskTitle + "\n" + taskDue + "\n" + meetLinks; // 組合訊息內容 sendToLine(message, lineAccessToken); messageNumber++; // 遞增訊息編號 } } } // 提取描述中的 MEET 連結 function getMeetLinks(notes) { var meetLinks = notes.match(/meet\.google\.com\/\S+/gi); if (meetLinks !== null) { return meetLinks.join('\n'); } else { return ""; } } function isSameDate(date1, date2) { return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate(); } function sendToLine(message, accessToken) { var url = "https://notify-api.line.me/api/notify"; var headers = { "Authorization": "Bearer " + accessToken, "Content-Type": "application/x-www-form-urlencoded" }; var payload = "message=" + encodeURIComponent(message); var options = { "method": "POST", "headers": headers, "payload": payload }; // 只有當 message 不為空時才發送通知 if (message.trim() !== "") { UrlFetchApp.fetch(url, options); } } ```