google-apigoogle-calendar-api

Webhooks for Event start on Google Calendar API


Is there a way to get a webhook when an event starts or slightly before an event starts?

Google Calendar API allows to create reminders on events. Is it possible to get a webhook when an event is activated or started?

For e.g., if I create an event for "Dec 15 2020 15:45 +0530", can I get a webhook at exactly that time, or a few minutes before?

Google may be using such a webhook to send out reminder emails or alarms. I want to use that to send notifications within my app.


Solution

  • There is currently an open Feature Request on Google Issue Tracker to add an API for reminders for Calendar.

    What you can do in this situation is to star the issue here and eventually add a comment.

    Workaround

    You can create a script using Apps Script that will get all the events from a particular day and check their starting times.

    function getEvents() {
        let today = new Date();
        let calendar = CalendarApp.getCalendarById(id);
        let events = calendar.getEventsForDay(today);
        let startTime = today.getHours();
        for (let i = 0; i < events.length; i++) {
            if (events[0].getStartTime() <= startTime) {
                // send email, notification etc;
            }
        }
    }
    

    Afterwards, you can add an installable time-driven trigger which can run every 15 minutes for example to trigger the execution of the above function.

    function createTrigger() {
      ScriptApp.newTrigger('getEvents')
          .timeBased()
          .everyMinutes(15)
          .create();
    }
    

    Note

    Please bear in mind that you can customize the script and the trigger in such a way that it suits your needs accordingly.

    Reference