Overview
This is a simple method running Google Apps Script by the event notification from Google Calendar.
Description
There are several event triggers in Google Apps Script. Ref1, Ref2 There is an event trigger for Google Calendar. The official document says An installable calendar event trigger runs when a user's calendar events are updated—created, edited, or deleted.
. Ref3 If I want to use the trigger when the event in the calendar is starts and finished, it is required to use Calendar API by preparing the URL for receiving from Google. Ref4, Ref5 Also, there is the method that the start time are retrieved from all event lists and run the script for each start time. But in this case, it is required to check new events and manage the time-driven triggers for running the script. I thought that those are the higher hurdle for me. So I thought a workaround.
Here, I would like to introduce the simple method for running Google Apps Script by the event notification from Google Calendar.
Flow
In order to use the event notification from Google Calendar as the trigger for running the Google Apps Script, IFTTT and Web Apps are used. The simple flow is as follows.
- An event is started at Google Calendar.
- Send the notification from Google Calendar to IFTTT.
- Request from IFTTT to Web Apps.
By above flow, Google Apps Script can be run when the event of Google Calendar is started.
Usage
Here, I would like to introduce how to set up this workaround.
1. Create new project of Google Apps Script.
You can see how to create it at this official document.
2. Copy and paste script.
Please copy and paste the following script to the script editor of the created GAS project.
function doGet(e) {
var p = e.parameter;
var object = {
title: p.title,
start: p.start,
end: p.end,
eventUrl: p.eventUrl
};
// do something
//
// Here, please put the script you want to run when the event is started.
//
return ContentService.createTextOutput("Done.");
}
3. Deploy Web Apps:
- On the script editor, Open a dialog box by “Publish” -> “Deploy as web app”.
- Select “Me” for “Execute the app as:”.
- Select “Anyone, even anonymous” for “Who has access to the app:”.
- This setting is for a test situation.
- You can also access with the access token by setting “Only myself” instead of “Anyone, even anonymous”.
- Click “Deploy” button as new “Project version”.
- Automatically open a dialog box of “Authorization required”.
- Click “Review Permissions”.
- Select own account.
- Click “Advanced” at “This app isn’t verified”.
- Click “Go to ### project name ###(unsafe)”
- Click “Allow” button.
- Click “OK”.
- Copy the URL of Web Apps. It’s like
https://script.google.com/macros/s/###/exec
.- When you modified the Google Apps Script, please redeploy as new version. By this, the modified script is reflected to Web Apps. Please be careful this.
4. Set up IFTTT:
Please log in to IFTTT and open “Create your own” with “Create”.
-
Set This of “If This Then That”.
-
Search “Google Calendar” at “Choose action service”.
-
Select “Any event starts” at “Choose trigger”.
-
Set “Which calendar?” and “Time before event starts”. Here, when “Time before event starts” is set as
0 minutes
, you can run the Google Apps Script when the event is started. -
Set That of “If This Then That”.
-
Search “Webhooks” at “Choose action service”.
-
Select “Make a web request” at “Choose action”.
-
Set
https://script.google.com/macros/s/###/exec?title={{Title}}&start={{Starts}}&end={{Ends}}&eventUrl={{EventUrl}}
to “URL” at Set “Complete action fields”. Please replace###
for the URL of your Web Apps. And click “Create action”.
The setup of this workaround is done.