Apps Script แจ้งเตือนอัปเดตครัวเรือน Netflix ทาง Line Notify (สำหรับดูบนทีวี)

แจ้งเตือนอัปเดตครัวเรือน Netflix ทาง Line Notify  (สำหรับดูบนทีวี)

สำหรับสายแชร์ที่ชอบดู Netflix บนทีวี แต่ดูไม่ค่อยบ่อย ด้วย Apps Script ของ Google Sheet เมื่อมีการร้องขอผ่านทาง Email โดยจะมีการแจ้ง อัปเดตครัวเรือน ส่ง URL ด้วย Line Notify เพื่อกดขออัพเดทเป็นครัวเรือน (เหมาะสำหรับเจ้าของ Email ที่ไม่สะดวกกดให้ ใช้สำหรับ Gmail หากเป็น Hotmail สามารถใช้ Power Automate แทนได้ครับ)




 

 function sendLineNotify(message) {

var token = ["///////API Token/////////"];

var options = {

"method": "post",

"payload": "message=" + message,

"headers": {

"Authorization": "Bearer " + token

}

}; 

UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);

}


function processNewEmails() {

  // 1. ใช้ GmailApp เพื่อดึงอีเมลใหม่

  var threads = GmailApp.search("label:Inbox from:info@account.netflix.com subject:ข้อมูลสำคัญ: วิธีอัปเดตครัวเรือน Netflix is:unread");


  if (threads.length > 0) {

    var thread = threads[0];

    var messages = thread.getMessages();


    for (var i = 0; i < messages.length; i++) {

      var message = messages[i];

        if (message.isUnread()) {

      var body = message.getPlainBody();


      // 2. แปลง HTML เป็นข้อความ

      var textBody = body.replace(/<[^>]+>/g, "");


      // 3. แบ่งข้อความเป็นส่วนๆ (โดยใช้ '\n' แทน '%0A')

      var lines = textBody.split('\n');


      // 4. กรองรายการที่มี URL ของ Netflix

      var netflixURLs = lines.filter(function(line) {

        return line.includes('https://www.netflix.com/account/update-primary-location');

      });


      // 5. กรองรายการที่มีคำว่า 'ขอโดย'

      var requestedLines = lines.filter(function(line) {

        return line.includes('สำหรับบัญชี');

      });


      // 6. สร้างข้อความจากรายการที่ผ่านการกรองและตัด '[' และ ']' ที่อยู่ที่สุดของข้อความ

      var compose1 = "";

      if (netflixURLs.length > 0) {

        compose1 = netflixURLs[netflixURLs.length - 1].replace(/\[|\]/g, "");

      }


      // 7. สร้างข้อความจากรายการที่ผ่านการกรองและตัด '[' และ ']' ที่อยู่ที่สุดของข้อความ

      var compose2 = "";

      if (requestedLines.length > 0) {

        compose2 = requestedLines[requestedLines.length - 1].replace(/\[|\]/g, "");

      }


    var msg = compose2 + '\n' + encodeURIComponent(compose1);

    sendLineNotify(msg);

    message.markRead();

        }

    }

  }

}

ตั้ง Trigger Apps Script



แสดงความคิดเห็น

0 ความคิดเห็น