google-apps-scriptgoogle-cloud-platformgoogle-workspacegoogle-workspace-add-ons

Google Calendar Workspace Add-on function not invoked


I have followed this guide to get a Calendar add-on up and running. The functions for Gmail are invoked and working correctly, but the Calendar function is not invoked at all - i.e. I see Executions of onGmailCompose, type Add-on in the AppsScript editor, but none for onCalendarEventOpen. Nothing for Calendar in the Logs Explorer either.

Manifest (appsscript.json):

{
  "timeZone": "Europe/Berlin",
  "dependencies": {
    "enabledAdvancedServices": []
  },
  "exceptionLogging": "STACKDRIVER",
  "oauthScopes": [
    "https://www.googleapis.com/auth/calendar.addons.execute",
    "https://www.googleapis.com/auth/calendar.readonly",
    "https://www.googleapis.com/auth/drive.addons.metadata.readonly",
    "https://www.googleapis.com/auth/gmail.addons.current.action.compose",
    "https://www.googleapis.com/auth/gmail.addons.current.message.readonly",
    "https://www.googleapis.com/auth/gmail.addons.execute",
    "https://www.googleapis.com/auth/script.locale"
  ],
  "runtimeVersion": "V8",
  "addOns": {
    "common": {
      "name": "Cats",
      "logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png",
      "useLocaleFromApp": true,
      "homepageTrigger": {
        "runFunction": "onHomepage",
        "enabled": true
      },
      "universalActions": [
        {
          "label": "Learn more about Cataas",
          "openLink": "https://cataas.com"
        }
      ]
    },
    "gmail": {
      "contextualTriggers": [
        {
          "unconditional": {},
          "onTriggerFunction": "onGmailMessage"
        }
      ],
      "composeTrigger": {
        "selectActions": [
          {
            "text": "Insert cat",
            "runFunction": "onGmailCompose"
          }
        ],
        "draftAccess": "NONE"
      }
    },
    "drive": {
      "onItemsSelectedTrigger": {
        "runFunction": "onDriveItemsSelected"
      }
    },
    "calendar": {
      "eventOpenTrigger": {
        "runFunction": "onCalendarEventOpen"
      },
      "eventUpdateTrigger": {
        "runFunction": "onCalendarEventUpdate"
      },
      "currentEventAccess": "READ"
    }
  }
}

functions:

function onCalendarEventOpen(e) {
  console.log(e);
  console.log("CALENDAR-EVENT-OPEN!!!")  
}

function onCalendarEventUpdate(e) {
  console.log("CALENDAR-EVENT-UPDATE!!!")
}

Screenshot of Executions tab (only Gmail, nothing for Calendar): Executions tab

Screenshot of Logs Explorer (again only Gmail, no logs from attempts to trigger in Calendar) Logs Explorer


Solution

  • Looks like you don't have sufficient access. You should also add the scope:

    https://www.googleapis.com/auth/calendar.addons.current.event.read
    

    Additionally, you must have the plug-in open for the code to run, so make sure you click its icon in the sidebar before performing any operations you expect to trigger your functions:

    Add on icon, circled