Tệp kê khai cho tiện ích bổ sung của Google Workspace

Tiện ích bổ sung sử dụng một tệp kê khai để định cấu hình một số thông tin chi tiết nhất định về ứng dụng và hoạt động của ứng dụng đó.

Tài liệu này trình bày thông tin chi tiết về cách định cấu hình tệp kê khai cho một Tiện ích bổ sung của Google Workspace.

Cấu trúc tệp kê khai cho các tiện ích bổ sung của Google Workspace

Tiện ích bổ sung của Google Workspace sử dụng tệp kê khai để xác định một số khía cạnh về giao diện và hành vi của tiện ích bổ sung.

Các thuộc tính tệp kê khai cho tiện ích bổ sung của Google Workspace được sắp xếp trong phần addOns của cấu trúc đối tượng tệp kê khai.

Cấu hình mẫu của tệp kê khai tiện ích bổ sung của Google Workspace

Tệp kê khai mẫu sau đây cho thấy phần của tệp kê khai xác định một Tiện ích bổ sung của Google Workspace, bao gồm các khía cạnh sau:

  • Phần addOns.common của tệp kê khai xác định tên, URL của biểu trưng, màu sắc và các chế độ cài đặt chung khác độc lập với máy chủ cho tiện ích bổ sung.
  • Tệp kê khai xác định một trang chủ chung, nhưng cũng xác định các trang chủ dành riêng cho Lịch, Drive, Tài liệu, Trang tính và Trang trình bày. Gmail sử dụng trang chủ mặc định.
  • Chế độ cài đặt tệp kê khai mẫu cho phép các tính năng sau:
  • Trường oauthScopes đặt phạm vi uỷ quyền cho dự án (Thường là bắt buộc đối với các tiện ích bổ sung).
  • (Chỉ dành cho Apps Script) Trường urlFetchWhitelist là một trường để đảm bảo rằng mọi điểm cuối đã tìm nạp đều khớp với danh sách tiền tố URL loại HTTPS. Để biết thêm thông tin, hãy xem bài viết URL của danh sách cho phép.

Các đường liên kết trong mẫu chuyển hướng đến phần mô tả về trường đó trong tài liệu tham khảo tệp kê khai tương ứng cho Apps Script và Tiện ích bổ sung HTTP cho Google Workspace.

Apps Script

{
  "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://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"
        }
      ],
      "createActionTriggers": [
        {
          "id": "exampleId",
          "labelText": "Example label text",
          "localizedLabelText": {
            "es": "Label text localized in Spanish"
          },
          "runFunction": "exampleFunction",
          "logoUrl": "https://www.example.com/images/case.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/"
  ]
}

HTTP

{
  "addOns": {
    "calendar": {
      "currentEventAccess": "READ_WRITE",
      "eventOpenTrigger": {
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=onCalendarEventOpen"
      },
      "eventUpdateTrigger": {
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=onCalendarEventUpdate"
      },
      "eventAttachmentTrigger": {
        "label": "My Event Attachment",
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=onCalendarEventAddAttachment"
      },
      "homepageTrigger": {
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=onCalendarHomePageOpen",
        "enabled": true
      }
    },
    "common": {
      "homepageTrigger": {
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=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://www.example.com/"
      ],
      "universalActions": [{
        "label": "Open settings",
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=getSettingsCard"
      }, {
        "label": "Open Help URL",
        "openLink": "https://www.example.com/help"
      }],
      "useLocaleFromApp": true
    },
    "drive": {
      "homepageTrigger": {
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=onDriveHomePageOpen",
        "enabled": true
      },
      "onItemsSelectedTrigger": {
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=onDriveItemsSelected"
      }
    },
    "gmail": {
      "composeTrigger": {
        "actions": [
          {
            "label": "Add images to email",
            "runFunction": "https://myownpersonaldomain.com/mypage?trigger=getInsertImageComposeCards"
          }
        ],
        "draftAccess": "METADATA"
      },
      "contextualTriggers": [
        {
          "unconditional": {},
          "onTriggerFunction": "https://myownpersonaldomain.com/mypage?trigger=onGmailMessageOpen"
        }
      ]
    },
    "docs": {
      "homepageTrigger": {
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=onEditorsHomepage"
      },
      "onFileScopeGrantedTrigger": {
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=onFileScopeGrantedEditors"
      },
      "linkPreviewTriggers": [
        {
          "runFunction": "https://myownpersonaldomain.com/mypage?trigger=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"
        }
      ],
      "createActionTriggers": [
        {
          "id": "exampleId",
          "labelText": "Example label text",
          "localizedLabelText": {
            "es": "Label text localized in Spanish"
          },
          "runFunction": "https://myownpersonaldomain.com/mypage?trigger=onCreateAction",
          "logoUrl": "https://www.example.com/images/case.png"
        }
      ]
    },
    "sheets": {
      "homepageTrigger": {
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=onEditorsHomepage"
      },
      "onFileScopeGrantedTrigger": {
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=onFileScopeGrantedEditors"
      }
    },
    "slides": {
      "homepageTrigger": {
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=onEditorsHomepage"
      },
      "onFileScopeGrantedTrigger": {
        "runFunction": "https://myownpersonaldomain.com/mypage?trigger=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"
  ]
}

URL của danh sách cho phép

Bạn sử dụng danh sách cho phép để chỉ định các URL cụ thể được phê duyệt trước cho tập lệnh hoặc tiện ích bổ sung của bạn truy cập. Danh sách cho phép giúp bảo vệ dữ liệu người dùng; khi bạn xác định danh sách cho phép, các dự án tập lệnh sẽ không thể truy cập vào các URL không có trong danh sách cho phép.

Trường này là không bắt buộc khi bạn cài đặt bản triển khai kiểm thử, nhưng là bắt buộc khi bạn tạo bản triển khai theo phiên bản.

Bạn sử dụng danh sách cho phép khi tập lệnh hoặc tiện ích bổ sung của bạn thực hiện các thao tác sau:

  • Truy xuất hoặc tìm nạp thông tin từ một vị trí bên ngoài (chẳng hạn như điểm cuối HTTPS) bằng dịch vụ UrlFetch Apps Script. Để đưa các URL vào danh sách cho phép tìm nạp, hãy đưa trường urlFetchWhitelist vào tệp kê khai.
  • Mở hoặc hiển thị một URL để phản hồi hành động của người dùng (Bắt buộc đối với các tiện ích bổ sung của Google Workspace giúp mở hoặc hiển thị URL không thuộc Google). Để đưa các URL vào danh sách cho phép mở, hãy đưa trường addOns.common.openLinkUrlPrefixes vào tệp kê khai.

Thêm tiền tố vào danh sách cho phép của bạn

Khi chỉ định danh sách cho phép trong tệp kê khai (bằng cách bao gồm trường addOns.common.openLinkUrlPrefixes hoặc urlFetchWhitelist), bạn phải đưa vào danh sách tiền tố URL. Các tiền tố mà bạn thêm vào tệp kê khai phải đáp ứng các yêu cầu sau:

  • Mỗi tiền tố phải là một URL hợp lệ.
  • Mỗi tiền tố phải sử dụng https://, không được dùng http://.
  • Mỗi tiền tố phải có một miền đầy đủ.
  • Mỗi tiền tố không được để trống đường dẫn. Ví dụ: https://www.google.com/ là hợp lệ nhưng https://www.google.com thì không.
  • Bạn có thể sử dụng ký tự đại diện để khớp với tiền tố miền con của URL.
  • Bạn có thể dùng một ký tự đại diện * duy nhất trong trường addOns.common.openLinkUrlPrefixes để so khớp với tất cả các đường liên kết. Tuy nhiên, bạn không nên làm như vậy vì việc này có thể khiến dữ liệu của người dùng gặp rủi ro và có thể kéo dài quá trình xem xét tiện ích bổ sung. Chỉ sử dụng ký tự đại diện nếu chức năng tiện ích bổ sung của bạn yêu cầu ký tự đại diện đó.

Khi xác định xem một URL có khớp với tiền tố trong danh sách cho phép hay không, các quy tắc sau sẽ áp dụng:

  • Kiểu khớp đường dẫn có phân biệt chữ hoa chữ thường.
  • Nếu tiền tố giống hệt với URL, thì tức là tiền tố đó khớp.
  • Nếu URL giống nhau hoặc là phần tử con của tiền tố, thì URL đó khớp.

Ví dụ: tiền tố https://example.com/foo khớp với các URL sau:

  • https://example.com/foo
  • https://example.com/foo/
  • https://example.com/foo/bar
  • https://example.com/foo?bar
  • https://example.com/foo#bar

Sử dụng ký tự đại diện

Bạn có thể sử dụng một ký tự đại diện duy nhất (*) để so khớp với một miền con cho cả trường urlFetchWhitelistaddOns.common.openLinkUrlPrefixes. Bạn không thể dùng nhiều ký tự đại diện để so khớp với nhiều miền con và ký tự đại diện phải đại diện cho tiền tố đứng đầu của URL.

Ví dụ: tiền tố https://*.example.com/foo khớp với các URL sau:

  • https://subdomain.example.com/foo
  • https://any.number.of.subdomains.example.com/foo

Tiền tố https://*.example.com/foo không khớp với các URL sau:

  • https://subdomain.example.com/bar (hậu tố không khớp)
  • https://example.com/foo (phải có ít nhất một miền con)

Một số quy tắc tiền tố được thực thi khi bạn cố gắng lưu tệp kê khai. Ví dụ: các tiền tố sau đây sẽ gây ra lỗi nếu chúng xuất hiện trong tệp kê khai khi bạn cố gắng lưu:

  • https://*.*.example.com/foo (nhiều ký tự đại diện bị cấm)
  • https://subdomain.*.example.com/foo (phải sử dụng ký tự đại diện làm tiền tố ở đầu)