3
votes

I'd like to use Google Apps Script to update a Google spreadsheet and send emails with the Gmail API whenever changes are made to a range of calendars that I own.

Can the Google Calendar push notifications be used with Google App Script or is another platform of some sort required?

I'm willing to learn whatever is necessary. I understand that a domain name is required receive the notifications.

I appreciate the help!

2
What do you mean by "push notification"? To what? You can use Apps Script to send an arbitrary payload to an arbitrary web address. If said payload and said endpoint correspond with that needed to send a GCM / FCM to the relevant end user of your installed Android/iOS application, then sure. - tehhowch
@tehhowch He's referring to push notifications as supported by the Calendar API not Web push notifications (which came about relatively recently in the last few years or so). - TheAddonDepot
@dimu The use of sheets and gmail api tags as well made me think OP wanted the an app to notify the user, as opposed to what seems like a webhook handler ;) - tehhowch

2 Answers

4
votes

Unfortunately this is not possible to achieve using Google App Script (at least not as of this writing).

You could try to create a Google Apps Script(GAS) web app and use its url as an endpoint for the Calendar API's push notifications. However, the data payload of a push notification sent by the Calendar API resides in custom HTTP headers which are not currently accessible from a GAS Web App.

There are alternative solutions but they will take you well outside of GSuite's ecosystem and they are unlikely to be free. But if you're up to the task in terms of programming skill and you can afford to invest monetarily in a platform then you should check out Google Cloud Functions. Its a pay-to-play cloud-based mirco-service but if you stay under the monthly free usage quota its practically free.

0
votes

This is quite a simple task if you're familiar with GAS (Google Apps Script), the code below is only a part of what's required (event.getLastUpdated is the trick) but it gives an idea of how to accomplish what you require. I also have this requirement & it works fine for me...

Set up a spreadsheet with the calendar details, & post your calendar info to it ...

  function getCalendars()
  {
   var cal = CalendarApp.getCalendarsByName(calName)[0]; // loop here with all your Calenders
   var events = cal.getEvents( date1, date2 ); // start date & end date
   for (var x in events ) 
   { 
      var event = events[x];
      var title = event.getTitle();
      var created = event.getDateCreated();
      var lastMod = event.getLastUpdated();
      var lastRead = getLastModifiedFromSpreadSheet();
      var diff= daysDiff(lastMod, read);
      if (diff > 0) {putNewDateInSpreadsheet(); doYourStuff;)
    }
  }

  function daysDiff(a, b) { // change to hours or minutes if required
  var oneDay = 1000 * 60 * 60 * 24;
  return Math.floor(b.getTime() / oneDay) - Math.floor(a.getTime() / oneDay);
  }