किसी एक्सटेंशन के लिए Cloud Functions लिखना

एक्सटेंशन बनाते समय, Cloud Functions का इस्तेमाल करके ठीक उसी तरह लिखें जैसा आप किसी ऐसे फ़ंक्शन को लिखते हैं जिसका इस्तेमाल सिर्फ़ तब किया जा सकता है, जब आपका प्रोजेक्ट मिल सकता है. extension.yaml फ़ाइल में, अपने फ़ंक्शन का एलान किया गया हो और जब उपयोगकर्ता आपका एक्सटेंशन इंस्टॉल करते हैं, तो ये फ़ंक्शन उनके प्रोजेक्ट.

इस्तेमाल करने के बारे में सामान्य जानकारी के लिए, Cloud Functions का दस्तावेज़ देखें Cloud Functions.

पहली और दूसरी जनरेशन के क्लाउड फ़ंक्शन

Firebase दोनों का इस्तेमाल करता है पहली जनरेशन और दूसरी जनरेशन के क्लाउड फ़ंक्शन. हालांकि, Firebase फ़िलहाल, एक्सटेंशन पर कुछ पाबंदियां लागू हैं. ये पाबंदियां, क्लाउड के किस वर्शन पर लागू होती हैं फ़ंक्शन का इस्तेमाल कर सकते हैं, जिसका इस्तेमाल कुछ ट्रिगर टाइप के साथ किया जा सकता है. इस वजह से, कई सारे एक्सटेंशन में पहली और दूसरी पीढ़ी के फ़ंक्शन का मिला-जुला रूप शामिल होता है.

यहां, हर तरह के ट्रिगर के लिए फ़ंक्शन जनरेट करने की सुविधा के बारे में बताया गया है.

ध्यान देने वाली खास बातें

  • कुछ फ़ंक्शन की डेफ़िनिशन के लिए, आपको ऐसी जानकारी देनी होगी जो extension.yaml फ़ाइल में बताया गया है. उदाहरण के लिए, Cloud Firestore में document() तरीका, जो देखने के लिए दस्तावेज़ का पैटर्न बताता है और इसके extension.yaml में इससे जुड़ी एलान के लिए, एक resource फ़ील्ड है जो एक जैसा बताता है.

    इन स्थितियों में, extension.yaml में बताया गया कॉन्फ़िगरेशन फ़ाइल का इस्तेमाल किया जाता है और फ़ंक्शन की परिभाषा में बताया गया कॉन्फ़िगरेशन है अनदेखा किया गया.

    फ़ंक्शन में कॉन्फ़िगर की गई वैल्यू दिखाना सामान्य तरीका है . इस पर दिए गए उदाहरण पेज इस पैटर्न को फ़ॉलो करता है.

  • Cloud Functions 1st gen SDK टूल का एक functions.config() तरीका है और functions:config:set सीएलआई निर्देश का इस्तेमाल करके, साथ काम किया जा सकता है पैरामीटर वाली वैल्यू, 1st gen के फ़ंक्शन में शामिल की जाती हैं. यहां यह तकनीक काम नहीं करती है Cloud Functions नहीं है और किसी एक्सटेंशन में बिलकुल भी काम नहीं करेगा. इसके बजाय, functions.params मॉड्यूल (सुझाया गया) या process.env.

TypeScript का इस्तेमाल करना

आपके खुद के एक्सटेंशन को बनाने के लिए, ज़्यादातर दस्तावेज़ों में वर्कफ़्लो के बारे में बताया गया है Firebase के लिए Cloud Functions के लिए JavaScript का इस्तेमाल करना. हालांकि, इसके बजाय आप यह लिख सकते हैं कि आपके फ़ंक्शन TypeScript का इस्तेमाल करके.

असल में, सभी आधिकारिक Firebase एक्सटेंशन टाइपस्क्रिप्ट में लिखे गए हैं. उन एक्सटेंशन की समीक्षा करके बेहतर तरीके से काम किया जा सकता है तरीकों का इस्तेमाल करें.

अगर आप टाइपस्क्रिप्ट में अपने एक्सटेंशन के फ़ंक्शन लिखते हैं, तो आपको एक्सटेंशन इंस्टॉल करने से पहले, इन बातों का ध्यान रखें:

  1. अपने एक्सटेंशन के सोर्स कोड को JavaScript में कंपाइल करें.

    firebase ext:dev:init निर्देश आपको अपने फ़ंक्शन लिखने के लिए TypeScript चुनने की अनुमति देता है. निर्देश आपको इंस्टॉल किया जा सकने वाला एक पूरा एक्सटेंशन और एक बिल्ड स्क्रिप्ट, जिसे npm run build की मदद से चलाया जा सकता है.

  2. अपनी package.json फ़ाइल में, main फ़ील्ड को जनरेट की गई JavaScript.

  3. यदि आप स्थानीय स्रोत से अपना एक्सटेंशन इंस्टॉल या अपलोड कर रहे हैं, पहले अपनी TypeScript फ़ाइलों को कंपाइल करें.

काम करने वाले फ़ंक्शन ट्रिगर

एचटीटीपी ट्रिगर

एचटीटीपी से ट्रिगर होने वाला फ़ंक्शन, सार्वजनिक https एंडपॉइंट पर डिप्लॉय किया जाता है और काम करता है जब एंडपॉइंट को ऐक्सेस किया जाता है.

Cloud Functions में, एचटीटीपी अनुरोधों के ज़रिए कॉल फ़ंक्शन देखें एचटीटीपी से ट्रिगर होने वाले फ़ंक्शन लिखने के बारे में जानकारी के लिए दस्तावेज़.

फ़ंक्शन की परिभाषा (सिर्फ़ 1st-gen)

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: ...

कॉल किए जा सकने वाले फ़ंक्शन

कॉल किए जा सकने वाले फ़ंक्शन, एचटीटीपी से ट्रिगर होने वाले फ़ंक्शन की तरह होते हैं. हालांकि, ये प्रोटोकॉल की मदद से आपके क्लाइंट-साइड कोड से आसानी से कॉल किया जा सकता है.

Cloud Functions दस्तावेज़ में अपने ऐप्लिकेशन से कॉल फ़ंक्शन देखें ताकि कॉल करने लायक फ़ंक्शन के इस्तेमाल के बारे में जानकारी मिल सके.

फ़ंक्शन की परिभाषा (सिर्फ़ 1st-gen)

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 दस्तावेज़ में फ़ंक्शन शेड्यूल करें देखें शेड्यूल किए गए फ़ंक्शन लिखने के बारे में जानकारी.

फ़ंक्शन की परिभाषा (सिर्फ़ 1st-gen)

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
अभी तक किसी भी व्यक्ति ने चेक इन नहीं किया है

टास्क की सूची के ट्रिगर

टास्क क्यू फंक्शन, आपके एक्सटेंशन के लाइफ़साइकल' पर ट्रिगर होता है इवेंट या जब एडमिन ऐक्सेस की मदद से, एक्सटेंशन की टास्क सूची में मैन्युअल तरीके से जोड़ा गया हो SDK टूल का TaskQueue.enqueue() तरीका.

लिखने के बारे में जानकारी के लिए, अपने एक्सटेंशन के लाइफ़साइकल इवेंट मैनेज करना देखें लाइफ़साइकल इवेंट को हैंडल करने वाले फ़ंक्शन.

Cloud Functions में, क्लाउड टास्क के साथ क्यू में फ़ंक्शन जोड़ें देखें टास्क सूची के फ़ंक्शन लिखने के बारे में जानकारी देने वाला दस्तावेज़.

फ़ंक्शन की परिभाषा (सिर्फ़ 1st-gen)

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 इवेंट मिलता है लॉग किया गया.

इनके लिए Cloud Functions दस्तावेज़ में Google Analytics ट्रिगर देखें Analytics से ट्रिगर होने वाले फ़ंक्शन लिखने के बारे में जानकारी.

फ़ंक्शन की परिभाषा (सिर्फ़ 1st-gen)

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

पुष्टि करना

पुष्टि करने वाला फ़ंक्शन तब काम करता है, जब उपयोगकर्ता को बनाया गया हो या मिटाया गया हो.

Cloud Functions में Firebase से पुष्टि करने वाले ट्रिगर देखें पुष्टि करने से ट्रिगर होने वाले फ़ंक्शन लिखने से जुड़ी जानकारी के लिए दस्तावेज़.

फ़ंक्शन की परिभाषा (सिर्फ़ 1st-gen)

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: ...

इस टेबल में बताया गया है कि पुष्टि करने के हर इवेंट के बारे में कैसे बताएं प्रकार:

Cloud Functions इवेंट ट्रिगर eventType ब्यौरा
onCreate() providers/firebase.auth/eventTypes/user.create नया उपयोगकर्ता बनाया गया
onDelete() providers/firebase.auth/eventTypes/user.delete उपयोगकर्ता का खाता मिटाया गया

Cloud Firestore

Cloud Firestore से ट्रिगर किया गया फ़ंक्शन तब काम करता है, जब कोई दस्तावेज़ बनाया जाता है, अपडेट किया जाता है, या मिटाया गया हो.

इनके लिए Cloud Functions दस्तावेज़ में Cloud Firestore ट्रिगर देखें Firestore से ट्रिगर होने वाले फ़ंक्शन लिखने के बारे में जानकारी.

फ़ंक्शन की परिभाषा (सिर्फ़ 1st-gen)

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 ट्रिगर किया गया फ़ंक्शन तब चलता है, जब किसी खास ईमेल पते के लिए मैसेज पब्लिश किया जाता है विषय.

इसके लिए Cloud Functions दस्तावेज़ में Pub/Sub ट्रिगर देखें Pub/Sub से ट्रिगर होने वाले फ़ंक्शन लिखने के बारे में जानकारी.

फ़ंक्शन की परिभाषा (सिर्फ़ 1st-gen)

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

रीयल टाइम डेटाबेस

रीयलटाइम डेटाबेस से ट्रिगर किया गया फ़ंक्शन तब चलता है, जब किसी पाथ से मेल खाता है पैटर्न बनाया, अपडेट किया जाता है या मिटाया जाता है.

Cloud Functions दस्तावेज़ में रीयल टाइम डेटाबेस ट्रिगर देखें का इस्तेमाल करें.

फ़ंक्शन की परिभाषा (सिर्फ़ 1st-gen)

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

रिमोट कॉन्फ़िगरेशन से ट्रिगर होने वाला फ़ंक्शन तब काम करता है, जब किसी प्रोजेक्ट का पैरामीटर टेंप्लेट अपडेट किया गया.

इसके लिए Cloud Functions दस्तावेज़ में रिमोट कॉन्फ़िगरेशन ट्रिगर देखें रिमोट कॉन्फ़िगरेशन से ट्रिगर होने वाले फ़ंक्शन लिखने के बारे में जानकारी.

फ़ंक्शन की परिभाषा (सिर्फ़ 1st-gen)

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 से ट्रिगर किया गया फ़ंक्शन तब काम करता है, जब कोई ऑब्जेक्ट बनाया जाता है, संग्रहित किया जाता है या हटाया गया है, या इसका मेटाडेटा बदलता है.

इनके लिए Cloud Functions दस्तावेज़ में Cloud Storage ट्रिगर देखें स्टोरेज से ट्रिगर होने वाले फ़ंक्शन लिखने के बारे में जानकारी.

फ़ंक्शन की परिभाषा (सिर्फ़ 1st-gen)

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

टेस्ट लैब

टेस्ट लैब से ट्रिगर किया गया फ़ंक्शन तब चलता है, जब कोई टेस्ट मैट्रिक्स अपने टेस्ट पूरे कर लेता है.

Cloud Functions दस्तावेज़ में Firebase टेस्ट लैब के ट्रिगर देखें ताकि टेस्ट लैब के ट्रिगर किए गए फ़ंक्शन लिखने के बारे में जानकारी मिल सके.

फ़ंक्शन की परिभाषा (सिर्फ़ 1st-gen)

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 सूचना ट्रिगर देखें अलर्ट से ट्रिगर होने वाले फ़ंक्शन लिखने के बारे में जानकारी.

फ़ंक्शन की परिभाषा (सिर्फ़ 2nd-gen के लिए)

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

परफ़ॉर्मेंस मॉनिटर करने से जुड़ी चेतावनी के ट्रिगर

जब परफ़ॉर्मेंस मॉनिटर करने की सुविधा किसी सूचना को पब्लिश करती है, तब परफ़ॉर्मेंस मॉनिटर करने की सुविधा चालू होती है.

इनके लिए Cloud Functions दस्तावेज़ में Firebase सूचना ट्रिगर देखें सूचना से ट्रिगर होने वाले फ़ंक्शन लिखने के बारे में जानकारी.

फ़ंक्शन की परिभाषा (सिर्फ़ 2nd-gen के लिए)

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 से ट्रिगर होने वाला फ़ंक्शन चलता है.

इनके लिए Cloud Functions दस्तावेज़ में Firebase सूचना ट्रिगर देखें अलर्ट से ट्रिगर होने वाले फ़ंक्शन लिखने के बारे में जानकारी.

फ़ंक्शन की परिभाषा (सिर्फ़ 2nd-gen के लिए)

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 से ट्रिगर किया गया फ़ंक्शन तब चलता है, जब कोई खास इवेंट टाइप किसी खास चैनल के लिए.

Cloud Functions में कस्टम इवेंट ट्रिगर बनाना और हैंडल करना देखें Eventarc से ट्रिगर होने वाले फ़ंक्शन लिखने से जुड़ी जानकारी के लिए दस्तावेज़.

अपने एक्सटेंशन से इवेंट पब्लिश भी किए जा सकते हैं, ताकि उपयोगकर्ताओं को इवेंट डालने का तरीका मिल सके कस्टम लॉजिक को जोड़ें. डेवलपर के दिए हुए कस्टम लॉजिक का इस्तेमाल करके एक्सटेंशन के साथ-साथ काम करते हैं.

फ़ंक्शन की परिभाषा (सिर्फ़ 2nd-gen के लिए)

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: ...

आपका एक्सटेंशन इंस्टॉल होने पर, चैनल पहले से मौजूद होना चाहिए. उदाहरण के लिए, अगर इसलिए, चैनल बनाने वाले किसी अन्य एक्सटेंशन के कस्टम इवेंट पर निर्भर रहने के साथ-साथ, अपने उपयोगकर्ताओं को पहले वह एक्सटेंशन इंस्टॉल करने का निर्देश दें.

ऊपर दिया गया उदाहरण "डिफ़ॉल्ट" के लिए एक कस्टम इवेंट ट्रिगर बनाएगा Firebase us-central1 क्षेत्र में चैनल. चैनल का नाम और इलाका तय किया जा सकता है पैरामीटर का इस्तेमाल करके कस्टमाइज़ किया जा सकता है. उदाहरण के लिए:


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}