Notifying New Release of Google APIs and Google Apps Script with Email using Google Apps Script

Gists

This is a sample script for notifying the new release of Google APIs and Google Apps Script with an email using Google Apps Script.

Recently, I published a sample script of “Retrieving Release Notes of Google Apps Script and Google APIs from RSS using Google Apps Script”. After this was published, I got an email that it wants to automatically notice the new release of Google APIs and Google Apps Script with an email. From this, I prepared a sample script as follows.

Sample script

Please set your email address to email in main. When you use this script, please manually run main function. By this, at 1st run, the new release in one month is checked as a test. And, the current date is stored in the PropertiesService. When you want to automatically obtain the notification, please install the time-driven trigger to main. For example, I run main one time at 00:00-01:00 every day. By this, when the new release is added, the email can be received.

// ref: https://tanaikech.github.io/2023/06/17/retrieving-release-notes-of-google-apps-script-and-google-apis-from-rss-using-google-apps-script/

const sendEmail_ = (obj) => MailApp.sendEmail(obj);

function getData_({ urls, checkDate }) {
  const reqs = urls.map((url) => ({ url, muteHttpExceptions: true }));
  const res = UrlFetchApp.fetchAll(reqs);
  const values = res.reduce((ar, r) => {
    if (r.getResponseCode() == 200) {
      const xml = XmlService.parse(r.getContentText());
      const root = xml.getRootElement();
      const ns = root.getNamespace();
      const updated = new Date(root.getChild("updated", ns).getValue());
      if (updated.getTime() > checkDate) {
        const title = root.getChild("title", ns).getValue();
        const entries = root.getChildren("entry", ns).map((e) => {
          const updated = new Date(e.getChild("updated", ns).getValue());
          const href = e.getChild("link", ns).getAttribute("href").getValue();
          const content = e.getChild("content", ns).getValue().trim();
          return [updated, href, content];
        });
        ar = [...ar, ...entries.map((e) => [title, updated, ...e])];
      }
    }
    return ar;
  }, []);
  return values;
}

// Please run this function.
function main() {
  const email = "###"; // Please set your email address. The message is sent to the email.

  try {
    const urls = [
      "https://developers.google.com/feeds/apps-script-release-notes.xml",
      "https://developers.google.com/feeds/drive-release-notes.xml",
      "https://developers.google.com/feeds/sheets-release-notes.xml",
      "https://developers.google.com/feeds/docs-release-notes.xml",
      "https://developers.google.com/feeds/slides-release-notes.xml",
      "https://developers.google.com/feeds/forms-release-notes.xml",
      "https://developers.google.com/feeds/calendar-release-notes.xml",
      "https://developers.google.com/feeds/gmail-release-notes.xml",
    ];

    const prop = PropertiesService.getScriptProperties();
    const checkDate = ((prop) => {
      const k = prop.getProperty("checkDate");
      if (!k) {
        const d = new Date();
        d.setMonth(d.getMonth() - 1);
        return d.getTime();
      }
      return new Date(k).getTime();
    })(prop);
    const values = getData_({ urls, checkDate });
    if (values.length > 0) {
      sendEmail_({
        to: email,
        subject: "Update release note.",
        body: JSON.stringify(values, null, 2),
      });
    }
    prop.setProperty("checkDate", new Date().toISOString());
  } catch (e) {
    sendEmail_({
      to: email,
      subject: "Error from Update release note.",
      body: JSON.stringify(e, null, 2),
    });
  }
}

 Share!