Triggers for Google Workspace add-ons (original) (raw)

Apps Script triggers cause a specified script function (the trigger function) to execute whenever a specified event occurs. Only certain events can cause triggers to fire, and each Google Workspace application supports a different set of events.

When a trigger fires, an event object is created. This JSON structure contains details about the event that occurred. The information in the event object structure is organized differently based on the trigger type.

Once the event object is created, Apps Script passes it as a parameter to the trigger function. The trigger function is a callback function that you must implement yourself, to take whatever actions are appropriate to respond to the event. For example, in a Google Workspace add-on that extends Gmail, you can define a trigger that creates a new card interface when the user opens a message thread. In this case, you implement a contextual callback function to create the cards making up the new UI using the data passed in theevent object.

This page provides guidelines on using triggers in Google Workspace add-on projects.

Manifest triggers

Unlike Editor add-ons, Google Workspace add-ons currently can't use Apps Script simple triggersInstead, they use triggers designed specifically for Google Workspace add-ons: manifest triggers.

Manifest triggers are defined completely in the Google Workspace add-on'smanifest. Examples of manifest triggers include the following:

In the above list, only homepage triggers are non-contextual; the rest are contextual triggers. See Manifestfor more information about manifest trigger definitions.

In addition to manifest triggers, Google Workspace add-ons can also use Apps Scriptinstallable triggers.

Restrictions

Manifest triggers have certain restrictions to their use.