为扩展程序编写 Cloud Functions 函数

创建扩展程序时,可使用 Cloud Functions 函数编写其逻辑,方法与编写只应用于您自己的项目中的函数大致相同。您可以在 extension.yaml 文件中声明函数,这样当用户安装您的扩展程序时,这些函数就会部署到他们的项目中。

如需了解有关使用 Cloud Functions 函数的一般信息,请参阅 Cloud Functions 文档。

第 1 代和第 2 代 Cloud Functions 函数

Firebase 同时支持第 1 代和第 2 代 Cloud Functions 函数。不过目前,Firebase Extensions 扩展程序在一些特定触发器类型可以用在哪一代 Cloud Functions 函数方面存在一定限制。因此,许多扩展程序都会混合包含第 1 代和第 2 代函数。

下文将就每种触发器类型具体支持哪一代函数进行说明。

特别注意事项

  • 某些函数定义要求您指定与 extension.yaml 文件中相同的信息。例如,Cloud Firestore 有一个 document() 方法,用于指定要监控的文档格式,并且它在 extension.yaml 中的相应声明也有一个 resource 字段,用于指定相同的内容。

    在这些情况下,系统会使用 extension.yaml 文件中指定的配置,并忽略函数定义中指定的配置。

    常见的做法是,无论如何都在函数定义中指定配置的值(用于记录用途)。此页面上的示例均遵循该做法。

  • Cloud Functions 第 1 代 SDK 中的 functions.config() 方法和 functions:config:set CLI 命令(用于处理第 1 代函数中的参数化值)已被弃用,它们在扩展程序中完全不起作用。请改用 functions.params 模块(推荐)或 process.env

使用 TypeScript

文档中有关开发您自己的扩展程序的内容大部分都是描述使用适用于 Cloud Functions for Firebase 的 JavaScript 的工作流。不过,您可以改用 TypeScript 编写您的函数。

实际上,所有官方 Firebase 扩展程序都是采用 TypeScript 编写的。您可以查看这些扩展程序,了解使用 TypeScript 编写扩展程序的一些最佳做法。

如果您采用 TypeScript 编写扩展程序的函数,则必须在安装扩展程序之前执行以下操作

  1. 将扩展程序的函数源代码编译为 JavaScript。

    您可以通过 firebase ext:dev:init 命令来选择使用 TypeScript 编写函数。该命令为您提供了一个完整的可安装扩展程序,以及一个可使用 npm run build 运行的构建脚本。

  2. package.json 文件中,确保将 main 字段指向生成的 JavaScript。

  3. 如果您是从本地来源安装或上传扩展程序,请先编译您的 TypeScript 文件。

支持的函数触发器

HTTP 触发器

HTTP 触发的函数会部署到一个公共 https 端点,并会在该端点被访问时运行。

如需了解如何编写 HTTP 触发的函数,请参阅 Cloud Functions 文档中的通过 HTTP 请求调用函数部分。

函数定义(仅适用于第 1 代)

import { https } from "firebase-functions/v1";

export const yourFunctionName = https.onRequest(async (req, resp) => {
  // ...
});

资源声明 (extension.yaml)

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      runtime: nodejs16
      httpsTrigger: {}
  - name: anotherFunction
    type: ...

Callable 函数

Callable 函数与 HTTP 触发的函数类似,但它们会实现一个协议,以方便用户通过客户端代码调用函数。

如需了解如何使用 Callable 函数,请参阅 Cloud Functions 文档中的从应用调用函数部分。

函数定义(仅适用于第 1 代)

import { https } from "firebase-functions/v1";

export const yourFunctionName = https.onCall(async (data, context) => {
  // ...
});

资源声明 (extension.yaml)

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      runtime: nodejs16
      httpsTrigger: {}
  - name: anotherFunction
    type: ...

预定函数触发器

预定函数根据可自定义的时间表反复运行。

如需了解如何编写预定函数,请参阅 Cloud Functions 文档中的安排函数运行时间部分。

函数定义(仅适用于第 1 代)

import { pubsub } from "firebase-functions/v1";

export const yourFunctionName = pubsub.schedule("every 6 hours").onRun((context) => {
  // ...
});

资源声明 (extension.yaml)

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      scheduleTrigger:
        schedule: 'every 5 minutes'
  - name: anotherFunction
    type: ...

以下是 scheduleTrigger 的可用子字段:

字段 说明
schedule
(必填)

您希望函数运行的频率。

此字段可以接受使用以下任一语法的字符串(必须用英文单引号括起来):

timeZone
(选填)

此时间计划采用的时区。

如果您希望用户在安装您的扩展程序时能够配置时间表,请向 extension.yaml 文件添加一个新参数,并在函数的 resource 声明中引用该参数:

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      scheduleTrigger:
        schedule: ${SCHEDULE_FREQUENCY}
  - name: anotherFunction
    type: ...

params:
  - param: SCHEDULE_FREQUENCY
    label: Schedule
    description: How often do you want to run yourFunctionName()?
    type: string
    default: 'every 5 minutes'  # Specifying a default is optional.
    required: true

任务队列触发器

任务队列函数可通过扩展程序的生命周期事件触发,也可在通过 Admin SDK 的 TaskQueue.enqueue() 方法手动添加到扩展程序的任务队列时触发。

如需了解如何编写函数来处理生命周期事件,请参阅处理扩展程序的生命周期事件

如需了解如何编写任务队列函数,请参阅 Cloud Functions 文档中的使用 Cloud Tasks 将函数加入队列部分。

函数定义(仅适用于第 1 代)

import { tasks } from "firebase-functions/v1";

export const yourFunctionName = tasks.taskQueue().onDispatch(async (data, context) => {
  // ...
});

资源声明 (extension.yaml)

resources:
  - name: myTaskFunction
    type: firebaseextensions.v1beta.function
    description: >-
      Perform a task when triggered by a lifecycle event
    properties:
      taskQueueTrigger: {}

taskQueueTrigger 属性设置为 {},或设置为用于调整任务队列速率限制和重试行为的选项的映射(请参阅调整任务队列)。

如果您希望通过扩展程序的生命周期事件触发函数,您可以添加一些 lifecycleEvents 记录并提供相应函数的名称,您还可以选择添加一条处理消息以在相应处理过程开始时在 Firebase 控制台中显示该消息。

lifecycleEvents:
  onInstall:
    function: myTaskFunction
    processingMessage: Resizing your existing images
  onUpdate:
    function: myOtherTaskFunction
    processingMessage: Setting up your extension
  onConfigure:
    function: myOtherTaskFunction
    processingMessage: Setting up your extension

Analytics

在有指定的 Analytics 事件被记录时,运行 Analytics 触发的函数。

如需了解如何编写 Analytics 触发的函数,请参阅 Cloud Functions 文档中的 Google Analytics(分析)触发器部分。

函数定义(仅适用于第 1 代)

import { analytics } from "firebase-functions/v1";

export const yourFunctionName = analytics.event("event_name").onLog((event, context) => {
  // ...
});

资源声明 (extension.yaml)

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: providers/google.firebase.analytics/eventTypes/event.log
        resource: projects/${PROJECT_ID}/events/ga_event
  - name: anotherFunction
    type: ...

如果您希望用户在安装您的扩展程序时能够配置要监听的 Analytics 事件,请向 extension.yaml 文件添加一个新参数,并在函数的 resource 声明中引用该参数:

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: providers/google.firebase.analytics/eventTypes/event.log
        resource: projects/${PROJECT_ID}/events/${EVENT_NAME}
  - name: anotherFunction
    type: ...

params:
  - param: EVENT_NAME
    label: Analytics event
    description: What event do you want to respond to?
    type: string
    default: ga_event  # Specifying a default is optional.
    required: true

Authentication

在有用户被创建或删除时,运行 Authentication 触发的函数。

如需了解如何编写 Authentication 触发的函数,请参阅 Cloud Functions 文档中的 Firebase Authentication 触发器部分。

函数定义(仅适用于第 1 代)

import { auth } from "firebase-functions/v1";

export const yourFunctionName = auth.user().onCreate((user, context) => {
  // ...
});

export const yourFunctionName2 = auth.user().onDelete((user, context) => {
  // ...
});

资源声明 (extension.yaml)

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: providers/firebase.auth/eventTypes/user.create
        resource: projects/${PROJECT_ID}
  - name: anotherFunction
    type: ...

下表说明如何指定受支持的每种 Authentication 事件类型:

Cloud Functions 事件触发器 eventType 说明
onCreate() providers/firebase.auth/eventTypes/user.create 创建了新用户
onDelete() providers/firebase.auth/eventTypes/user.delete 删除了用户

Cloud Firestore

在有文档被创建、更新或删除时,运行 Cloud Firestore 触发的函数。

如需了解如何编写 Firestore 触发的函数,请参阅 Cloud Functions 文档中的 Cloud Firestore 触发器部分。

函数定义(仅适用于第 1 代)

import { firestore } from "firebase-functions/v1";

export const yourFunctionName = firestore.document("collection/{doc_id}")
  .onCreate((snapshot, context) => {
    // ...
  });

export const yourFunctionName2 = firestore.document("collection/{doc_id}")
  .onUpdate((change, context) => {
    // ...
  });

export const yourFunctionName3 = firestore.document("collection/{doc_id}")
  .onDelete((snapshot, context) => {
    // ...
  });

export const yourFunctionName4 = firestore.document("collection/{doc_id}")
  .onWrite((change, context) => {
    // onWrite triggers on creation, update, and deletion.
    // ...
  });

资源声明 (extension.yaml)

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: providers/cloud.firestore/eventTypes/document.write
        resource: projects/${PROJECT_ID}/databases/(default)/documents/collection/{documentID}
  - name: anotherFunction
    type: ...

下表说明如何指定受支持的每种 Cloud Firestore 事件类型:

Cloud Functions 事件触发器 eventType 说明
onCreate() providers/cloud.firestore/eventTypes/document.create 有新文档被创建
onDelete() providers/cloud.firestore/eventTypes/document.delete 有文档被删除
onUpdate() providers/cloud.firestore/eventTypes/document.update 更新了文档
onWrite() providers/cloud.firestore/eventTypes/document.write 创建、删除或更新了文档

如果您希望用户在安装您的扩展程序时能够配置文档路径,请在 extension.yaml 文件中添加一个新参数,并在函数的 resource 声明中引用该参数:

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: providers/cloud.firestore/eventTypes/document.write
        resource: projects/${PROJECT_ID}/databases/(default)/documents/${YOUR_DOCUMENT_PATH}
  - name: anotherFunction
    type: ...

params:
  - param: YOUR_DOCUMENT_PATH
    label: Cloud Firestore path
    description: Where do you want to watch for changes?
    type: string
    default: path/to/{documentID}  # Specifying a default is optional.
    required: true

Pub/Sub

在有消息发布到特定主题时,运行 Pub/Sub 触发的函数。

如需了解如何编写 Pub/Sub 触发的函数,请参阅 Cloud Functions 文档中的 Pub/Sub 触发器部分。

函数定义(仅适用于第 1 代)

import { pubsub } from "firebase-functions/v1";

export const yourFunctionName = pubsub.topic("topic_name").onPublish((message, context) => {
  // ...
});

资源声明 (extension.yaml)

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: google.pubsub.topic.publish
        resource: projects/${PROJECT_ID}/topics/topic-name
  - name: anotherFunction
    type: ...

如果您希望用户在安装您的扩展程序时能够配置 Pub/Sub 主题,请在 extension.yaml 文件中添加一个新参数,并在函数的 resource 声明中引用该参数:

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: google.pubsub.topic.publish
        resource: projects/${PROJECT_ID}/topics/${PUBSUB_TOPIC}
  - name: anotherFunction
    type: ...

params:
  - param: PUBSUB_TOPIC
    label: Pub/Sub topic
    description: Which Pub/Sub topic do you want to watch for messages?
    type: string
    default: topic-name  # Specifying a default is optional.
    required: true

Realtime Database

在有与指定模式匹配的路径被创建、更新或删除时,运行 Realtime Database 触发的函数。

如需了解如何编写 RTDB 触发的函数,请参阅 Cloud Functions 文档中的 Realtime Database 触发器部分。

函数定义(仅适用于第 1 代)

import { database } from "firebase-functions/v1";

export const yourFunctionName = database.ref("path/to/{item}")
  .onCreate((snapshot, context) => {
    // ...
  });

export const yourFunctionName2 = database.ref("path/to/{item}")
  .onUpdate((change, context) => {
    // ...
  });

export const yourFunctionName3 = database.ref("path/to/{item}")
  .onDelete((snapshot, context) => {
    // ...
  });

export const yourFunctionName4 = database.ref("path/to/{item}")
  .onWrite((change, context) => {
    // onWrite triggers on creation, update, and deletion.
    // ...
  });

资源声明 (extension.yaml)

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: providers/google.firebase.database/eventTypes/ref.create
        # DATABASE_INSTANCE (project's default instance) is an auto-populated
        # parameter value. You can also specify an instance.
        resource: projects/_/instances/${DATABASE_INSTANCE}/refs/path/to/{itemId}
  - name: anotherFunction
    type: ...

下表说明如何指定受支持的每种 Cloud Firestore 事件类型:

Cloud Functions 事件触发器 eventType 说明
onCreate() providers/google.firebase.database/eventTypes/ref.create 创建了数据
onDelete() providers/google.firebase.database/eventTypes/ref.delete 删除了数据
onUpdate() providers/google.firebase.database/eventTypes/ref.update 更新了数据
onWrite() providers/google.firebase.database/eventTypes/ref.write 创建、删除或更新了数据

如果您希望用户在安装您的扩展程序时能够配置要监控的路径,请在 extension.yaml 文件中添加一个新参数,并在函数的 resource 声明中引用该参数:

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: providers/google.firebase.database/eventTypes/ref.create
        # DATABASE_INSTANCE (project's default instance) is an auto-populated
        # parameter value. You can also specify an instance.
        resource: projects/_/instances/${DATABASE_INSTANCE}/refs/${DB_PATH}
  - name: anotherFunction
    type: ...

params:
  - param: DB_PATH
    label: Realtime Database path
    description: Where do you want to watch for changes?
    type: string
    default: path/to/{itemId}  # Specifying a default is optional.
    required: true

Remote Config

在有项目的参数模板被更新时,运行 Remote Config 触发的函数。

如需了解如何编写 Remote Config 触发的函数,请参阅 Cloud Functions 文档中的 Remote Config 触发器部分。

函数定义(仅适用于第 1 代)

import { remoteConfig } from "firebase-functions/v1";

export const yourFunctionName = remoteConfig.onUpdate((version, context) => {
  // ...
});

资源声明 (extension.yaml)

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: google.firebase.remoteconfig.update
        resource: projects/${PROJECT_ID}
  - name: anotherFunction
    type: ...

Cloud Storage

在有对象被创建、归档或删除或有对象的元数据发生更改时,运行 Cloud Storage 触发的函数。

如需了解如何编写 Storage 触发的函数,请参阅 Cloud Functions 文档中的 Cloud Storage 触发器部分。

函数定义(仅适用于第 1 代)

import { storage } from "firebase-functions/v1";

export const yourFunctionName = storage.object().onFinalize((object, context) => {
  // ...
});

export const yourFunctionName2 = storage.object().onMetadataUpdate((object, context) => {
  // ...
});

export const yourFunctionName3 = storage.object().onArchive((object, context) => {
  // ...
});

export const yourFunctionName4 = storage.object().onDelete((object, context) => {
  // ...
});

资源声明 (extension.yaml)

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: google.storage.object.finalize
        # STORAGE_BUCKET (project's default bucket) is an auto-populated
        # parameter. You can also specify a bucket.
        resource: projects/_/buckets/${STORAGE_BUCKET}
  - name: anotherFunction
    type: ...

下表说明如何指定受支持的每种 Cloud Storage 事件类型:

Cloud Functions 事件触发器 eventType 说明
onFinalize() google.storage.object.finalize 创建了对象
onMetadataUpdate() google.storage.object.metadataUpdate 更新了对象元数据
onArchive() google.storage.object.archive 归档了对象
onDelete() google.storage.object.delete 有对象被删除

如果您希望用户在安装您的扩展程序时能够配置存储桶,请在 extension.yaml 文件中添加一个新参数,并在函数的 resource 声明中引用该参数:

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: google.storage.object.finalize
        resource: projects/_/buckets/${YOUR_BUCKET}
  - name: anotherFunction
    type: ...

params:
  - param: YOUR_BUCKET
    label: Cloud Storage bucket
    description: Which bucket do you want to watch for changes?
    type: selectResource
    resourceType: storage.googleapis.com/Bucket
    default: ${STORAGE_BUCKET}  # Specifying a default is optional.
    required: true

Test Lab

在测试矩阵完成其测试时,运行 Test Lab 触发的函数。

如需了解如何编写 Test Lab 触发的函数,请参阅 Cloud Functions 文档中的 Firebase Test Lab 触发器部分。

函数定义(仅适用于第 1 代)

import { testLab } from "firebase-functions/v1";

export const yourFunctionName = testLab.testMatrix().onComplete((matrix, context) => {
  // ...
});

资源声明 (extension.yaml)

resources:
  - name: yourFunctionName
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: google.testing.testMatrix.complete
        resource: projects/${PROJECT_ID}/testMatrices/{matrixId}
  - name: anotherFunction
    type: ...

Crashlytics 提醒触发器

在 Crashlytics 发布提醒时,运行 Crashlytics 触发的函数。

如需了解如何编写提醒触发的函数,请参阅 Cloud Functions 文档中的 Firebase 提醒触发器部分。

函数定义(仅适用于第 2 代)

import {
  onNewFatalIssuePublished,
  onNewNonfatalIssuePublished,
  onNewAnrIssuePublished,
  onRegressionAlertPublished,
  onVelocityAlertPublished,
  onStabilityDigestPublished,
} from "firebase-functions/v2/alerts/crashlytics";

export const yourFunctionName = onNewFatalIssuePublished((event) => {
  // ...
});

export const yourFunctionName2 = onNewNonfatalIssuePublished((event) => {
  // ...
});

export const yourFunctionName3 = onNewAnrIssuePublished((event) => {
  // ...
});

export const yourFunctionName4 = onRegressionAlertPublished((event) => {
  // ...
});

export const yourFunctionName5 = onVelocityAlertPublished((event) => {
  // ...
});

export const yourFunctionName6 = onStabilityDigestPublished((event) => {
  // ...
});

资源声明 (extension.yaml)

apis:
  - apiName: eventarc.googleapis.com
    reason: Powers all events and triggers
  - apiName: run.googleapis.com
    reason: Powers 2nd-gen functions

resources:
  - name: yourfunctionname
    type: firebaseextensions.v1beta.v2function
    properties:
      buildConfig:
        runtime: nodejs16
      serviceConfig:
        availableMemory: 512M
      eventTrigger:
        eventType: google.firebase.firebasealerts.alerts.v1.published
        triggerRegion: global
        eventFilters:
          - attribute: alerttype
            value: crashlytics.newFatalIssue
  - name: anotherFunction
    type: ...

可以为 alerttype 使用以下值

  • crashlytics.newFatalIssue
  • crashlytics.newNonfatalIssue
  • crashlytics.regression
  • crashlytics.stabilityDigest
  • crashlytics.velocity
  • crashlytics.newAnrIssue

Performance Monitoring 提醒触发器

在 Performance Monitoring 发布提醒时,运行 Performance Monitoring 触发的函数。

如需了解如何编写提醒触发的函数,请参阅 Cloud Functions 文档中的 Firebase 提醒触发器部分。

函数定义(仅适用于第 2 代)

import { onThresholdAlertPublished } from "firebase-functions/v2/alerts/performance";

export const yourFunctionName = onThresholdAlertPublished((event) => {
  // ...
});

资源声明 (extension.yaml)

apis:
  - apiName: eventarc.googleapis.com
    reason: Powers all events and triggers
  - apiName: run.googleapis.com
    reason: Powers 2nd-gen functions

resources:
  - name: yourfunctionname
    type: firebaseextensions.v1beta.v2function
    properties:
      buildConfig:
        runtime: nodejs16
      serviceConfig:
        availableMemory: 512M
      eventTrigger:
        eventType: google.firebase.firebasealerts.alerts.v1.published
        triggerRegion: global
        eventFilters:
          - attribute: alerttype
            value: performance.threshold
  - name: anotherFunction
    type: ...

App Distribution 提醒触发器

在 App Distribution 发布提醒时,运行 App Distribution 触发的函数。

如需了解如何编写提醒触发的函数,请参阅 Cloud Functions 文档中的 Firebase 提醒触发器部分。

函数定义(仅适用于第 2 代)

import {
  onNewTesterIosDevicePublished,
  onInAppFeedbackPublished
} from "firebase-functions/v2/alerts/appDistribution";

export const yourFunctionName = onNewTesterIosDevicePublished((event) => {
  // ...
});

export const yourFunctionName2 = onInAppFeedbackPublished((event) => {
  // ...
});

资源声明 (extension.yaml)

apis:
  - apiName: eventarc.googleapis.com
    reason: Powers all events and triggers
  - apiName: run.googleapis.com
    reason: Powers 2nd-gen functions

resources:
  - name: yourfunctionname
    type: firebaseextensions.v1beta.v2function
    properties:
      buildConfig:
        runtime: nodejs16
      serviceConfig:
        availableMemory: 512M
      eventTrigger:
        eventType: google.firebase.firebasealerts.alerts.v1.published
        triggerRegion: global
        eventFilters:
          - attribute: alerttype
            value: appDistribution.inAppFeedback
  - name: anotherFunction
    type: ...

可以为 alerttype 使用以下值

  • appDistribution.newTesterIosDevice
  • appDistribution.inAppFeedback

自定义事件触发器 (Eventarc)

在有特定类型的事件发布到特定渠道时,运行 Eventarc 触发的函数。

如需了解如何编写 Eventarc 触发的函数,请参阅 Cloud Functions 文档中的创建和处理自定义事件触发器部分。

您还可以从扩展程序发布事件,为用户提供一种方法来将自定义逻辑插入您的扩展程序。请参阅在扩展程序中使用开发者提供的自定义逻辑

函数定义(仅适用于第 2 代)

import { onCustomEventPublished } from "firebase-functions/v2/eventarc";

export const yourFunctionName = onCustomEventPublished((event) => {
  // ...
});

资源声明 (extension.yaml)

apis:
  - apiName: eventarc.googleapis.com
    reason: Powers all events and triggers
  - apiName: run.googleapis.com
    reason: Powers 2nd-gen functions

resources:
  - name: yourfunctionname
    type: firebaseextensions.v1beta.v2function
    properties:
      # LOCATION is a user-configured parameter value specified by the user
      # during installation.
      location: ${param:LOCATION}
      buildConfig:
        runtime: nodejs16
      serviceConfig:
        availableMemory: 512M
        timeoutSeconds: 60
      eventTrigger:
        eventType: firebase.extensions.storage-resize-images.v1.complete
        channel: projects/${param:PROJECT_ID}/locations/us-central1/channels/firebase
  - name: anotherFunction
    type: ...

用户在安装您的扩展程序时,该渠道必须已存在。例如,如果您依赖于另一个将创建渠道的扩展程序中的自定义事件,请指示用户先安装该扩展程序。

上面的示例将为 us-central1 区域中的“default”Firebase 渠道创建一个自定义事件触发器。您可以使用参数自定义渠道名称和区域。例如:


params:
  - param: EVENTARC_CHANNEL_NAME
    label: Eventarc channel name
    description: What is the name of the Eventarc channel.
    default: firebase
    type: string
    required: true

resources:
  - name: yourfunctionname
    type: firebaseextensions.v1beta.v2function
    properties:
      location: ${param:LOCATION}
      eventTrigger:
        eventType: firebase.extensions.storage-resize-images.v1.complete
        channel: projects/${param:PROJECT_ID}/locations/${param:LOCATION}/channels/${param:EVENTARC_CHANNEL_NAME}