擴充功能發布商總覽
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Firebase Extension 會因應 HTTP 要求,或來自其他 Firebase 和 Google 產品 (例如 Firebase 雲端通訊、Cloud Firestore 或 Pub/Sub) 的觸發事件,執行特定工作或一組工作。
您可以建立擴充功能供個人使用,也可以在 Firebase 擴充功能中心與全球分享。舉例來說,擴充功能可以執行應用程式經常需要的特定工作,也可以讓您更輕鬆地存取貴公司的 API。建構擴充功能後,即可與他人共用。這些使用者可以安裝及設定擴充功能,以便在自己的 Firebase 專案中使用。
擴充功能的結構
擴充功能主要有三個元件:
- 以 JavaScript 或 TypeScript 編寫的 Cloud Functions 程式碼
- 描述擴充功能的中繼資料
- 協助使用者設定及使用擴充功能的說明文件
如要開發擴充功能,請將這些元件組合成下列結構:
example-extension
├── functions
│ ├── integration-tests
│ │ ├── extensions
│ │ │ └── example-extension.env
│ │ ├── firebase.json
│ │ └── integration-test.spec.js
│ ├── index.js
│ └── package.json
├── README.md
├── PREINSTALL.md
├── POSTINSTALL.md
├── CHANGELOG.md
├── icon.png
└── extension.yaml
functions
目錄包含以 JavaScript 或 TypeScript 編寫的 Cloud Functions 程式碼。這段程式碼會回應 Firebase 和 Google 服務觸發的事件,執行擴充功能的任務。
extension.yaml
檔案包含擴充功能的中繼資料,例如觸發條件和 IAM 存取角色,以及您希望使用者可設定的任何參數。
PREINSTALL
、POSTINSTALL
和 CHANGELOG
檔案是擴充功能必須具備的最低文件量。這些檔案可協助使用者瞭解擴充功能的功能、使用方式和更新內容。您也應提供圖示,方便使用者辨識擴充功能。使用者探索、安裝及管理擴充功能時,Firebase 控制台、Firebase CLI 和擴充功能中心會顯示這些檔案的內容。
建立擴充功能後,您可以使用 Firebase CLI 將其安裝至專案,或發布至擴充功能中心,供使用者探索並安裝至專案。
擴充功能可以與哪些產品互動?
Firebase 擴充功能是透過 Cloud Functions 運作,因此您可以從兩個方面思考可能的整合:哪些產品可以觸發擴充功能的函式?以及觸發後,擴充功能的函式可以與哪些產品互動?
支援的函式觸發條件
手動觸發條件
首先,您可以手動觸發函式。Firebase Extensions 和 Cloud Functions 支援兩種手動觸發函式的方式:
- HTTP 觸發條件:將函式部署至 HTTP 端點
- 可呼叫函式:使用 Firebase 用戶端 SDK,直接從 iOS、Android 或網頁用戶端程式碼呼叫 Cloud Functions。
從擴充功能公開 HTTP 端點後,擴充功能就能與任何支援 Webhook 的網路服務整合。使用者安裝擴充功能後,就能透過可呼叫函式,使用 Firebase SDK 做為用戶端程式庫,存取擴充功能實作的 API。
Firebase 服務觸發條件
大多數 Firebase 產品都會發出事件,可觸發擴充功能的 Cloud Functions。
- Analytics:在 Analytics 記錄事件時觸發函式
- 應用程式發布:在應用程式發布觸發快訊時觸發函式
- 驗證:在使用者建立及刪除帳戶時觸發函式
- Cloud Firestore:在建立、更新或刪除頁面時觸發函式
- Cloud Storage:在物件上傳至 bucket、封存或從 bucket 刪除時觸發函式
- Crashlytics:在 Crashlytics 觸發快訊時觸發函式
- Performance Monitoring:在 Performance Monitoring 觸發快訊時觸發函式
- 即時資料庫:在建立、更新或刪除資料時觸發函式
- 遠端設定:在參數更新時觸發函式
- Test Lab:在 Test Lab 觸發快訊時觸發函式
Google Cloud 服務觸發條件
擴充功能也可以包含函式,從多項非 Firebase 的 Google Cloud 服務觸發:
- Cloud Pub/Sub:擴充功能可以包含函式,在事件發布至可設定的 Pub/Sub 主題時觸發。
- Cloud Scheduler:擴充功能可以包含在設定時間表上執行的函式
- Cloud Tasks:擴充功能可以包含可透過 Cloud Tasks 加入佇列的函式。Firebase Extensions 會使用這項功能,讓擴充功能作者編寫函式,以回應擴充功能的「生命週期」事件,例如首次安裝至專案、升級至新版本,以及重新設定。
- Eventarc:擴充功能可以包含在事件發布至可設定的 Eventarc 管道時觸發的函式;反之,擴充功能也可以將自己的事件發布至 Eventarc 管道,讓使用者定義自己的函式,從擴充功能的事件觸發。
支援的函式
擴充功能的 Cloud 函式觸發後,通常可進行各種整合。以下列出 Cloud Functions 的部分功能:
- 讀取、寫入及以其他方式與任何使用支援 IAM 角色的 Firebase 或 Google Cloud 服務互動。
- 與提供 Web API 的任何第三方服務搭配使用。
- 如果您提供 Web API,請使用自訂服務。
- 執行大多數 JavaScript 程式庫,包括 TensorFlow.js、Express.js 等。
如何建構擴充功能
入門教學課程會逐步說明如何建構、測試及發布完整擴充功能,建議您透過這項課程瞭解如何建構擴充功能。
開始使用
完成一次入門指南後,您可以參考個別主題指南,瞭解建構擴充功能時的各項工作:
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[],[],null,["\u003cbr /\u003e\n\nA Firebase Extension performs a specific task or set of tasks in response to\nHTTP requests or triggering events from other Firebase and Google products, like\nFirebase Cloud Messaging, Cloud Firestore, or Pub/Sub.\n\nYou can build your own extension for personal use or to share with the world in\nthe Firebase Extensions Hub. For example, your extension can perform a specific\ntask that your app regularly needs, or it can make it easier to access one of\nyour company's APIs. After you build your extension, you can share it with\nothers. Those users can install and configure the extension for use in their own\nFirebase projects.\n\nStructure of an extension\n\nYou can think of an extension as having three main components:\n\n- Cloud Functions code, in JavaScript or TypeScript\n- Metadata that describes your extension\n- Documentation to help your users configure and use your extension\n\nTo develop an extension, you assemble these components into the following\nstructure: \n\n example-extension\n ├── functions\n │ ├── integration-tests\n │ │ ├── extensions\n │ │ │ └── example-extension.env\n │ │ ├── firebase.json\n │ │ └── integration-test.spec.js\n │ ├── index.js\n │ └── package.json\n ├── README.md\n ├── PREINSTALL.md\n ├── POSTINSTALL.md\n ├── CHANGELOG.md\n ├── icon.png\n └── extension.yaml\n\n- The `functions` directory contains your Cloud Functions code in JavaScript or TypeScript. This is the code that performs the extension's tasks in response to events triggered by Firebase and Google services.\n- The `extension.yaml` file contains metadata about your extension, such as its triggers and IAM access roles, as well as any parameters you want to be user-configurable.\n- The `PREINSTALL`, `POSTINSTALL`, and `CHANGELOG` files are the minimum documentation your extension must have. These files help your users learn what your extension does, how to use it, and what updates you've made. You should also provide an icon to help users recognize your extension. The Firebase console, Firebase CLI, and Extensions Hub display the contents of these files when users explore, install, and manage your extension.\n\nAfter you have created your extension, you can use the Firebase CLI to install\nit into a project or publish it to the Extensions Hub, where anyone can discover\nand install it into their projects.\n\nWhat products can my extension interact with?\n\nBecause a Firebase extension does its work using Cloud Functions, you can think\nof the question of possible integrations in two ways: *What products can trigger\nmy extension's functions?* and *Once triggered, what products can my extension's\nfunctions interact with?*\n\nSupported function triggers\n\nManual triggers\n\nFirst of all, you can manually trigger a function. Firebase Extensions and Cloud\nFunctions support two ways of manually triggering functions:\n\n- HTTP triggers: deploy a function to an HTTP endpoint\n- Callable functions: call your Cloud Functions directly from your iOS, Android, or web client code, using the Firebase client SDKs.\n\nBy exposing HTTP endpoints from your extension, your extension can potentially\nintegrate with any web service that supports webhooks. With callable functions,\nusers who install your extension can use the Firebase SDKs as a client library\nfor accessing the API your extension implements.\n\nFirebase service triggers\n\nMost Firebase products emit events that can trigger an extension's Cloud\nFunctions.\n\n- **Analytics:** trigger functions when Analytics logs an event\n- **App Distribution:** trigger functions when App Distribution triggers an alert\n- **Authentication:** trigger functions when users create and delete accounts\n- **Cloud Firestore:** trigger functions when pages are created, updated, or deleted\n- **Cloud Storage**: trigger functions when objects are uploaded, archived, or deleted from buckets\n- **Crashlytics:** trigger functions when Crashlytics triggers an alert\n- **Performance Monitoring:** trigger functions when Performance Monitoring triggers an alert\n- **Realtime Database:** trigger functions when data is created, updated, or deleted\n- **Remote Config:** trigger functions when a parameter is updated\n- **Test Lab:** trigger functions when Test Lab triggers an alert\n\nGoogle Cloud service triggers\n\nAn extension can also include functions that trigger off several non-Firebase\nGoogle Cloud services:\n\n- **Cloud Pub/Sub**: an extension can include functions that trigger when events are posted to a configurable Pub/Sub topic.\n- **Cloud Scheduler**: an extension can include functions that run on a set schedule\n- **Cloud Tasks**: an extension can include functions that can be queued using Cloud Tasks. Firebase Extensions uses this capability to let you, as an extension author, write functions that respond to an extension's \"lifecycle\" events: being installed in a project for the first time, being upgraded to a new version, and being reconfigured.\n- **Eventarc** : an extension can include functions that trigger when events are published to a configurable Eventarc channel; conversely, an extension can publish its own events to an Eventarc channel in order to enable users to define their own functions that trigger from an *extension's* events.\n\nSupported from functions\n\nOnce an extension's Cloud Function has been triggered, the range of possible\nintegrations is generally open ended. Here are some highlights of what you can\ndo from a Cloud Function:\n\n- Read, write, and otherwise interact with any **Firebase** or **Google Cloud** service that uses a [supported IAM role](/docs/extensions/publishers/access#supported-roles).\n- Work with any **third-party service** that provides a web API.\n- Work with your **custom services** if you provide a web API.\n- Run most JavaScript libraries, including **TensorFlow.js** , **Express.js,** and so on.\n\nHow to build an extension\n\nThe [Get Started](/docs/extensions/publishers/get-started) tutorial walks you through\nthe process of building, testing, and publishing a complete extension, and is\nthe recommended way to learn how to build one.\n\n[Get Started](/docs/extensions/publishers/get-started)\n\nAfter you've gone through the getting started guide once, you can refer to the\nindividual topic guides, which explain each of the tasks involved in building\nyour own extension:\n\n- [Write functions for an extension](/docs/extensions/publishers/functions)\n- [Use parameters in an extension](/docs/extensions/publishers/parameters)\n- [Set up appropriate access for an extension](/docs/extensions/publishers/access)\n- [Respond to extension lifecycle events](/docs/extensions/publishers/lifecycle-events)\n- [Add user hooks to an extension](/docs/extensions/publishers/user-hooks)\n- [Create user documentation for your extension](/docs/extensions/publishers/user-documentation)\n- [Publish an extension on Extensions Hub](/docs/extensions/publishers/upload-and-publish)\n- [Complete extension.yaml reference](/docs/extensions/reference/extension-yaml)"]]