Apps Script プロジェクトでは、マニフェスト ファイルを使用して、スクリプトとその操作に関する特定の詳細を構成します。マニフェストを表示および編集する方法については、マニフェストをご覧ください。
このドキュメントでは、Google Workspace アドオンのマニフェストを構成する方法について説明します。
Google Workspace アドオンのマニフェスト構造
Google Workspace アドオンでは、Apps Script プロジェクト マニフェスト ファイルを使用して、アドオンの外観と動作のいくつかの側面を定義します。Google Workspace アドオンのマニフェスト プロパティは、マニフェスト オブジェクト構造の addOns
セクションにまとめられています。
Google Workspace アドオン マニフェストの構成例
次のマニフェスト サンプルは、Google Workspace アドオンを定義するマニフェスト ファイルのセクションを示しています。以下の内容が含まれます。
- マニフェストの
addOns.common
セクションでは、アドオンの名前、ロゴの URL、色など、ホストに依存しない全般的な設定を定義します。 - このマニフェストでは、共通のホームページを定義しますが、カレンダー、ドライブ、ドキュメント、スプレッドシート、スライド固有のホームページも定義します。Gmail ではデフォルトのホームページが使用されます。
- サンプル マニフェスト設定を使用すると、次のことが可能になります。
- カレンダーの
eventOpen
トリガーとeventUpdated
トリガー、2 つのカレンダーの会議ソリューション。 - 2 つの普遍的なアクション。
- ドライブ
onItemsSelectedTrigger
。 - Gmail では Compose アクションとコンテキスト トリガーが使用されます。
- ドキュメントの
linkPreviewTrigger
。このトリガーの詳細については、スマートチップを使用してリンクをプレビューするをご覧ください。 - ドキュメント、スプレッドシート、スライドのファイル固有のインターフェース。
- カレンダーの
oauthScopes
フィールドでは、プロジェクトの認可スコープを設定します(通常はアドオンで必須)。urlFetchWhitelist
フィールドは、取得したエンドポイントが HTTPS URL 接頭辞の指定リストと一致するようにするフィールドです。このフィールドは、テストデプロイでは省略可能ですが、デプロイでは必須です。詳しくは、URL を許可リストに追加するをご覧ください。
サンプル内のリンクから、マニフェスト リファレンス ドキュメントに記載されているフィールドの説明に移動できます。
// Sample configuration of the addOns section in a manifest file: { "addOns": { "calendar": { "createSettingsUrlFunction": "getConferenceSettingsPageUrl", "conferenceSolution": [{ "id": "my-video-conf", "logoUrl": "https://lh3.googleusercontent.com/...", "name": "My Video Conference", "onCreateFunction": "onCreateMyVideoConference" }, { "id": "my-streamed-conf", "logoUrl": "https://lh3.googleusercontent.com/...", "name": "My Streamed Conference", "onCreateFunction": "onCreateMyStreamedConference" }], "currentEventAccess": "READ_WRITE", "eventOpenTrigger": { "runFunction": "onCalendarEventOpen" }, "eventUpdateTrigger": { "runFunction": "onCalendarEventUpdate" }, "eventAttachmentTrigger": { "label": "My Event Attachment", "runFunction": "onCalendarEventAddAttachment" }, "homepageTrigger": { "runFunction": "onCalendarHomePageOpen", "enabled": true } }, "common": { "homepageTrigger": { "runFunction": "onDefaultHomePageOpen", "enabled": true }, "layoutProperties": { "primaryColor": "#ff392b", "secondaryColor": "#d68617" }, "logoUrl": "https://ssl.gstatic.com/docs/script/images/logo/script-64.png", "name": "Demo Google Workspace Add-on", "openLinkUrlPrefixes": [ "https://mail.google.com/", "https://script.google.com/a/google.com/d/", "https://drive.google.com/a/google.com/file/d/", "https://en.wikipedia.org/wiki/", "https://www.example.com/" ], "universalActions": [{ "label": "Open settings", "runFunction": "getSettingsCard" }, { "label": "Open Help URL", "openLink": "https://www.example.com/help" }], "useLocaleFromApp": true }, "drive": { "homepageTrigger": { "runFunction": "onDriveHomePageOpen", "enabled": true }, "onItemsSelectedTrigger": { "runFunction": "onDriveItemsSelected" } }, "gmail": { "composeTrigger": { "selectActions": [ { "text": "Add images to email", "runFunction": "getInsertImageComposeCards" } ], "draftAccess": "METADATA" }, "contextualTriggers": [ { "unconditional": {}, "onTriggerFunction": "onGmailMessageOpen" } ] }, "docs": { "homepageTrigger": { "runFunction": "onEditorsHomepage" }, "onFileScopeGrantedTrigger": { "runFunction": "onFileScopeGrantedEditors" }, "linkPreviewTriggers": [ { "runFunction": "onLinkPreview", "patterns": [ { "hostPattern": "example.com", "pathPrefix": "example-path" } ], "labelText": "Link preview", "localizedLabelText": { "es": "Link preview localized in Spanish" }, "logoUrl": "https://www.example.com/images/smart-chip-icon.png" } ] }, "sheets": { "homepageTrigger": { "runFunction": "onEditorsHomepage" }, "onFileScopeGrantedTrigger": { "runFunction": "onFileScopeGrantedEditors" } }, "slides": { "homepageTrigger": { "runFunction": "onEditorsHomepage" }, "onFileScopeGrantedTrigger": { "runFunction": "onFileScopeGrantedEditors" } }, "oauthScopes": [ "https://www.googleapis.com/auth/calendar.addons.execute", "https://www.googleapis.com/auth/calendar.addons.current.event.read", "https://www.googleapis.com/auth/calendar.addons.current.event.write", "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.metadata", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/script.external_request", "https://www.googleapis.com/auth/script.locale", "https://www.googleapis.com/auth/script.scriptapp", "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/documents.currentonly", "https://www.googleapis.com/auth/spreadsheets.currentonly", "https://www.googleapis.com/auth/presentations.currentonly", "https://www.googleapis.com/auth/workspace.linkpreview" ], "urlFetchWhitelist": [ "https://www.example.com/myendpoint/" ], }
許可リストの URL
許可リストを使用して、スクリプトまたはアドオンによるアクセスが事前に承認されている特定の URL を指定します。許可リストは、ユーザーデータの保護に役立ちます。許可リストを定義すると、スクリプト プロジェクトは、許可リストに登録されていない URL にアクセスできません。
許可リストは、スクリプトまたはアドオンが次のアクションを実行するときに使用します。
- Apps Script の
UrlFetch
サービスを使用して、外部の場所(HTTPS エンドポイントなど)から情報を取得またはフェッチします。URL の取得を許可リストに登録するには、マニフェスト ファイルにurlFetchWhitelist
フィールドを追加します。 - ユーザー アクションに応じて URL を開くか表示します(Google 以外の URL を開くか表示する Google Workspace アドオンで必須)。開く URL を許可リストに登録するには、マニフェスト ファイルに
addOns.common.openLinkUrlPrefixes
フィールドを追加します。
許可リストに接頭辞を追加する
マニフェスト ファイルで(addOns.common.openLinkUrlPrefixes
フィールドまたは urlFetchWhitelist
フィールドを追加して)許可リストを指定する場合は、URL 接頭辞のリストを含める必要があります。マニフェストに追加するプレフィックスは、次の要件を満たしている必要があります。
- 接頭辞は有効な URL である必要があります。
- 各接頭辞には
http://
ではなくhttps://
を使用する必要があります。 - 各プレフィックスには完全なドメインが必要です。
- 各接頭辞には空でないパスが必要です。たとえば、
https://www.google.com/
は有効ですが、https://www.google.com
は無効です。 - URL サブドメインの接頭辞の照合にはワイルドカードを使用できます。
addOns.common.openLinkUrlPrefixes
フィールドに単一の*
ワイルドカードを使用してすべてのリンクに一致させることができますが、ユーザーのデータが危険にさらされ、アドオンの審査プロセスが長引く可能性があるため、おすすめしません。ワイルドカードは、アドオン機能で必要な場合にのみ使用してください。
URL が許可リストに登録されたプレフィックスと一致するかどうかを判断する際は、次のルールが適用されます。
- パスの一致では大文字と小文字が区別されます。
- プレフィックスが URL と同一の場合は一致します。
- URL がプレフィックスと同じか、その子 URL であれば一致します。
たとえば、接頭辞 https://example.com/foo
は次の URL と一致します。
https://example.com/foo
https://example.com/foo/
https://example.com/foo/bar
https://example.com/foo?bar
https://example.com/foo#bar
ワイルドカードの使用
1 つのワイルドカード文字(*
)を使用して、urlFetchWhitelist
フィールドと addOns.common.openLinkUrlPrefixes
フィールドの両方でサブドメインを照合できます。複数のワイルドカードを使用して複数のサブドメインに一致させることはできません。ワイルドカードは URL の先頭の接頭辞を表す必要があります。
たとえば、接頭辞 https://*.example.com/foo
は次の URL と一致します。
https://subdomain.example.com/foo
https://any.number.of.subdomains.example.com/foo
接頭辞 https://*.example.com/foo
は次の URL と一致しません。
https://subdomain.example.com/bar
(接尾辞の不一致)https://example.com/foo
(少なくとも 1 つのサブドメインが存在する必要があります)
マニフェストを保存しようとしたときに、一部のプレフィックス ルールが適用されます。たとえば、マニフェストに次の接頭辞が含まれている場合、保存しようとするとエラーが発生します。
https://*.*.example.com/foo
(複数のワイルドカードは禁止されています)https://subdomain.*.example.com/foo
(先頭の接頭辞としてワイルドカードを使用する必要があります)