扩展程序发布商概览
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Firebase Extensions 扩展程序可用来执行一个或一组特定任务,以响应 HTTP 请求或来自其他 Firebase 和 Google 产品(如 Firebase Cloud Messaging、Cloud Firestore 或 Pub/Sub)的触发性事件。
您可以构建自己的扩展程序供个人使用,也可以通过 Firebase Extensions Hub 将其分享给世界各地的用户。例如,您的扩展程序可以执行一项您的应用经常需要的特定任务,或者可让您的应用更轻松地访问公司的某项 API。构建扩展程序后,您可以将其分享给其他人;以便他们可以在自己的 Firebase 项目中安装、配置并使用您的扩展程序。
扩展程序的结构
您可以将扩展程序视为包含三大组成部分:
- Cloud Functions 函数代码(采用 JavaScript 或 TypeScript 编写)
- 描述扩展程序的元数据
- 帮助用户配置和使用您的扩展程序的文档
如需开发扩展程序,您需要将这三大组成部分封装到下面的结构中:
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
目录包含 Cloud Functions 函数代码(采用 JavaScript 或 TypeScript 编写)。您的扩展程序正是通过这些代码来执行特定任务,以响应各项 Firebase 和 Google 服务触发的事件。
extension.yaml
文件包含有关您的扩展程序的元数据(例如其触发器和 IAM 访问角色),以及您希望让用户可以配置的任何参数。
PREINSTALL
、POSTINSTALL
和 CHANGELOG
文件是您的扩展程序必须包含的文档。这些文件有助于您的用户了解扩展程序的用途、扩展程序的使用方式,以及您进行过哪些更新。您还应提供一个图标来帮助用户识别您的扩展程序。在用户探索、安装和管理您的扩展程序时,Firebase 控制台、Firebase CLI 和 Extensions Hub 都会显示这些文件的内容。
创建扩展程序后,您可以使用 Firebase CLI 将其安装到项目中,也可以将其发布到 Extensions Hub,在这里,任何人都可以发现该扩展程序并将其安装到自己的项目中。
我的扩展程序可以与哪些产品交互?
由于 Firebase Extensions 扩展程序是使用 Cloud Functions 函数来执行任务,因此您可以从下面两个方面来考虑可能的集成问题:哪些产品可能会触发扩展程序的函数?在这些函数被触发后,它们又可以与哪些产品交互?
支持的函数触发器
手动触发器
首先,您可以手动触发函数。Firebase Extensions 扩展程序和 Cloud Functions 函数支持通过下面两种方式来手动触发函数:
- HTTP 触发器:将函数部署到 HTTP 端点
- Callable 函数:使用 Firebase 客户端 SDK 直接通过 iOS、Android 或 Web 客户端代码调用 Cloud Functions 函数。
从您的扩展程序公开 HTTP 端点后,扩展程序就能够与支持 webhook 的 Web 服务进行集成。若是使用 Callable 函数,安装了您的扩展程序的用户则可以使用 Firebase SDK 作为客户端库来访问您的扩展程序实现的 API。
Firebase 服务触发器
大多数 Firebase 产品发出的事件都可以触发扩展程序的 Cloud Functions 函数。
- Analytics:在 Analytics 记录事件时触发函数
- App Distribution:在 App Distribution 触发提醒时触发函数
- Authentication:在用户创建和删除账号时触发函数
- Cloud Firestore:在有页面被创建、更新或删除时触发函数
- Cloud Storage:在存储桶中有对象被上传、归档或删除时触发函数
- Crashlytics:在 Crashlytics 触发提醒时触发函数
- Performance Monitoring:在 Performance Monitoring 触发提醒时触发函数
- Realtime Database:在有数据被创建、更新或删除时触发函数
- Remote Config:在有参数被更新时触发函数
- Test Lab:在 Test Lab 触发提醒时触发函数
Google Cloud 服务触发器
扩展程序还可以包含由一些 Google Cloud 服务(非 Firebase 服务)触发的函数:
- Cloud Pub/Sub:扩展程序可以包含在有事件被发布到可配置的 Pub/Sub 主题时触发的函数。
- Cloud Scheduler:扩展程序可以包含按设定的时间表运行的函数
- Cloud Tasks:扩展程序可以包含可使用 Cloud Tasks 加入队列的函数。Firebase Extensions 扩展程序有了这一功能后,您作为扩展程序的创作者,可以编写函数来响应扩展程序的“生命周期”事件:首次在项目中安装时、升级到新版本时、进行重新配置时。
- Eventarc:扩展程序可以包含在有事件被发布到可配置的 Eventarc 渠道时触发的函数;反之,扩展程序亦可以将自己的事件发布到 Eventarc 渠道,以便用户可以定义自己的函数来响应扩展程序的事件。
受函数支持
扩展程序的 Cloud Functions 函数被触发后,基本就可以进行自由集成。下面介绍了 Cloud Functions 函数的一些主要用法:
- 与使用受支持的 IAM 角色的任何 Firebase 或 Google Cloud 服务进行读写及其他方式的交互。
- 与提供了 Web API 的任何第三方服务进行交互。
- 与您自己的自定义服务进行交互(如果您提供了 Web API)。
- 运行大多数 JavaScript 库,包括 TensorFlow.js、Express.js 等。
如何构建扩展程序
使用入门教程将引导您完成构建、测试和发布完整扩展程序的流程,同时也是了解如何构建扩展程序的推荐方法。
开始
在通读使用入门指南后,您可以参考各个主题指南,这些具体的指南会介绍构建您自己的扩展程序所涉及的每项任务:
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-12。
[null,null,["最后更新时间 (UTC):2025-08-12。"],[],[],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)"]]