Google Workspace アドオンのトリガー
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Apps Script トリガーは、指定されたイベントが発生するたびに、指定されたスクリプト関数(トリガー関数)を実行します。トリガーを起動できるのは特定のイベントのみで、各 Google Workspace アプリケーションは異なるイベントのセットをサポートしています。
トリガーが起動すると、イベント オブジェクトが作成されます。この JSON 構造には、発生したイベントの詳細が含まれています。イベント オブジェクト構造の情報は、トリガータイプに基づいて異なる方法で整理されます。
イベント オブジェクトが作成されると、Apps Script はそれをパラメータとしてトリガー関数に渡します。トリガー関数は、イベントに応答するために適切なアクションを実行するコールバック関数であり、自分で実装する必要があります。たとえば、Gmail を拡張する Google Workspace アドオンでは、ユーザーがメッセージ スレッドを開いたときに新しいカード インターフェースを作成するトリガーを定義できます。この場合、コンテキスト コールバック関数を実装して、イベント オブジェクトで渡されたデータを使用して新しい UI を構成するカードを作成します。
このページでは、Google Workspace アドオン プロジェクトでトリガーを使用する際のガイドラインについて説明します。
マニフェスト トリガー
Editor アドオンとは異なり、Google Workspace アドオンは現在 Apps Script のシンプルなトリガーを使用できません。代わりに、Google Workspace アドオン専用に設計されたトリガー(マニフェスト トリガー)を使用します。
マニフェスト トリガーは、Google Workspace アドオンのマニフェストで完全に定義されます。マニフェスト トリガーの例を次に示します。
- アドオンのホームページをビルドして表示するホームページ トリガー。
- カレンダーの予定を開くトリガー。カレンダーの予定が開かれたときに新しいカードを表示したり、他のアクションを実行したりします。
- ユーザーがカレンダーの予定を編集して保存したときに、新しいカードを表示したり、他のアクションを実行したりするカレンダーの予定の更新トリガー。
- ユーザーがドライブで 1 つ以上のファイルまたはフォルダを選択したときに、新しいカードを表示したり、他のアクションを実行したりする Drive onItemsSelected トリガー。
- Gmail 作成トリガー。ユーザーが Gmail 作成ウィンドウでアドオンを開いたときにアドオンカードを表示します。
- ユーザーが Gmail メッセージを開いたときに新しいカードを表示したり、他のアクションを実行したりする Gmail コンテキスト トリガー。
- ユーザーが現在のエディタ ドキュメントで
drive.file
OAuth スコープの承認を付与したときに新しいカードを表示する、エディタの onFileScopeGranted トリガー。
上記のリストでは、ホームページ トリガーのみがコンテキスト トリガーではなく、残りはコンテキスト トリガーです。マニフェスト トリガーの定義の詳細については、マニフェストをご覧ください。
マニフェスト トリガーに加えて、Google Workspace アドオンでは Apps Script のインストール可能なトリガーも使用できます。
制限事項
マニフェスト トリガーの使用には、一定の制限があります。
- これらのトリガーは Google Workspace アドオン プロジェクトでのみ使用され、他のアプリケーションでは使用されません。
- これらのトリガーは、アドオンのコードではなく、アドオンのマニフェストで定義されているため、Apps Script の
Script
サービスを使用して作成または変更することはできません。
- Gmail のコンテキスト トリガーでは、現在
unconditional
条件のみを使用できます。つまり、コンテンツに関係なく、すべてのメール メッセージでコンテキスト トリガーが起動します。
- 各アドオンで設定できるトリガーは、ユーザーごと、ドキュメントごとに、各タイプ 1 つのみです。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-31 UTC。
[null,null,["最終更新日 2025-07-31 UTC。"],[[["\u003cp\u003eApps Script triggers execute a specific function when a defined event occurs within a Google Workspace application.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Workspace add-ons utilize manifest triggers, defined in the add-on's manifest, to respond to events like opening a document or composing an email.\u003c/p\u003e\n"],["\u003cp\u003eManifest triggers can be contextual, reacting to specific user actions within a document or application, or non-contextual, like those that build the add-on's homepage.\u003c/p\u003e\n"],["\u003cp\u003eWhile manifest triggers offer event-driven functionality, they have limitations, including restrictions on their use and creation methods.\u003c/p\u003e\n"]]],["Apps Script triggers initiate a script function when specific events occur, creating an event object with event details. This object is then passed to a user-implemented trigger function, enabling actions based on the event. Google Workspace add-ons use manifest triggers, defined in the add-on's manifest, to trigger actions like displaying cards on homepage, when opening/updating Calendar events, selecting Drive items, or opening a message in Gmail. Contextual triggers and installable triggers are also supported but with some restrictions.\n"],null,["# Triggers for Google Workspace add-ons\n\n[Apps Script triggers](/apps-script/guides/triggers) cause a specified script\nfunction (the *trigger function*) to execute whenever a specified event\noccurs. Only certain events can cause triggers to fire, and each\nGoogle Workspace application supports a different set of events.\n\nWhen a trigger fires, an *event object* is created. This JSON structure\ncontains details about the event that occurred. The information in the event\nobject structure is organized differently based on the trigger type.\n\nOnce the event object is created, Apps Script passes it as a parameter to the\ntrigger function. The trigger function is a callback function that you must\nimplement yourself, to take whatever actions are appropriate to respond to the\nevent. For example, in a\nGoogle Workspace add-on that extends Gmail, you can\ndefine a trigger that creates a new card interface when the user opens a message\nthread. In this case, you implement a contextual callback function to create\nthe cards making up the new UI using the data passed in the\n[event object](/workspace/add-ons/concepts/event-objects).\n\nThis page provides guidelines on using triggers in\nGoogle Workspace\nadd-on projects.\n\nManifest triggers\n-----------------\n\nUnlike Editor add-ons, Google Workspace add-ons\ncurrently can't use Apps Script [simple triggers](/apps-script/guides/triggers)\nInstead, they use triggers designed specifically for\nGoogle Workspace add-ons: *manifest triggers*.\n\nManifest triggers are defined completely in the\nGoogle Workspace add-on's\n[manifest](/workspace/add-ons/concepts/workspace-manifests). Examples of manifest triggers include the\nfollowing:\n\n- **Homepage triggers** that build and display the add-on homepage.\n- **Calendar eventOpen triggers** that display a new card or take other actions when a Calendar event is opened.\n- **Calendar eventUpdate triggers** that display a new card or take other actions when a user edits and saves a Calendar event.\n- **Drive onItemsSelected triggers** that display a new card or take other actions when a user selects one or more files or folders in Drive.\n- **Gmail compose triggers** that display an add-on card when the user opens the add-on in the Gmail compose window.\n- **Gmail contextual triggers** that display a new card or take other actions when the user opens a Gmail message.\n- **Editor onFileScopeGranted triggers** that display a new card when users grant authorization for the `drive.file` OAuth scope in the current Editor document.\n\nIn the above list, only homepage triggers are non-contextual; the rest are\ncontextual triggers. See [Manifest](/workspace/add-ons/concepts/workspace-manifests)\nfor more information about manifest trigger definitions.\n\nIn addition to manifest triggers, Google Workspace\nadd-ons can also use Apps Script\n[installable triggers](/apps-script/guides/triggers/installable).\n\n### Restrictions\n\nManifest triggers have certain restrictions to their use.\n\n- These triggers are only used in Google Workspace add-on projects; they have no purpose in any other application.\n- Since they are defined in the add-on manifest and not in its code, you can't use the Apps Script [`Script`](/apps-script/reference/script) service to create or modify these triggers.\n- Gmail contextual triggers currently can only have an `unconditional` criteria. This means contextual triggers fire for every email message, regardless of content.\n- Each add-on can only have one trigger of each type, per user, per document."]]