एक्सटेंशन बनाते समय, Cloud Functions का इस्तेमाल करके उसकी लॉजिक लिखी जाती है. यह तरीका, आपके प्रोजेक्ट में इस्तेमाल होने वाले फ़ंक्शन को लिखने के तरीके जैसा ही होता है. extension.yaml फ़ाइल में, अपने फ़ंक्शन के बारे में जानकारी दें. जब उपयोगकर्ता आपका एक्सटेंशन इंस्टॉल करते हैं, तो ये फ़ंक्शन उनके प्रोजेक्ट में डिप्लॉय हो जाते हैं.
का इस्तेमाल करने के बारे में सामान्य जानकारी पाने के लिए, Cloud Functions का दस्तावेज़ देखें Cloud Functions.
पहली और दूसरी पीढ़ी के Cloud Functions
Firebase, पहली और दूसरी पीढ़ी के Cloud Functions, दोनों के साथ काम करता है. हालांकि, फ़िलहाल Firebase एक्सटेंशन पर कुछ पाबंदियां हैं. इनके तहत, कुछ ट्रिगर टाइप के साथ Cloud Functions की किस पीढ़ी का इस्तेमाल किया जा सकता है. इस वजह से, कई एक्सटेंशन में पहली और दूसरी पीढ़ी के फ़ंक्शन का मिक्स इस्तेमाल किया जाता है.
यहां हर ट्रिगर टाइप के लिए, फ़ंक्शन जनरेशन की सुविधा के बारे में बताया गया है.
ध्यान देने वाली खास बातें
कुछ फ़ंक्शन की परिभाषाओं के लिए, आपको ऐसी जानकारी देनी होती है जो
extension.yamlफ़ाइल में भी दी जाती है. उदाहरण के लिए, Cloud Firestore मेंdocument()तरीका होता है. इससे, निगरानी के लिए दस्तावेज़ का पैटर्न तय किया जाता है. साथ ही,extension.yamlमें इसकी जानकारी देने वालेresourceफ़ील्ड में भी यही जानकारी दी जाती है.ऐसी स्थितियों में,
extension.yamlफ़ाइल में तय किया गया कॉन्फ़िगरेशन इस्तेमाल किया जाता है. साथ ही, फ़ंक्शन की परिभाषा में तय किए गए कॉन्फ़िगरेशन को अनदेखा कर दिया जाता है.दस्तावेज़ के लिए, फ़ंक्शन की परिभाषा में कॉन्फ़िगर की गई वैल्यू तय करना आम बात है. इस पेज पर दिए गए उदाहरण, इसी पैटर्न को फ़ॉलो करते हैं.
Cloud Functions पहली पीढ़ी के SDK टूल में,
functions.config()तरीका औरfunctions:config:setसीएलआई कमांड होता है. इनका इस्तेमाल, पहली पीढ़ी के फ़ंक्शन में पैरामीटर वाली वैल्यू के साथ काम करने के लिए किया जा सकता है. Cloud Functions में, इस तकनीक के इस्तेमाल पर रोक लगा दी गई है. साथ ही, यह किसी एक्सटेंशन में काम नहीं करेगी.Cloud Functions इसके बजाय,functions.paramsमॉड्यूल (सुझाया गया) याprocess.envका इस्तेमाल करें.
TypeScript का इस्तेमाल करना
अपना एक्सटेंशन डेवलप करने से जुड़े ज़्यादातर दस्तावेज़ों में, वर्कफ़्लो के लिए JavaScript का इस्तेमाल करके Cloud Functions for Firebaseके बारे में बताया गया है. हालांकि, आपके पास TypeScript का इस्तेमाल करके अपने फ़ंक्शन लिखने का विकल्प भी होता है.
असल में, Firebase के सभी आधिकारिक Firebase एक्सटेंशन TypeScript में लिखे जाते हैं. अपने एक्सटेंशन के लिए TypeScript का इस्तेमाल करने के सबसे सही तरीके जानने के लिए, उन एक्सटेंशन की समीक्षा की जा सकती है.
अगर आपने अपने एक्सटेंशन के फ़ंक्शन, TypeScript में लिखे हैं, तो आपको एक्सटेंशन इंस्टॉल करने से पहले यह काम करना होगा:
अपने एक्सटेंशन के फ़ंक्शन के सोर्स कोड को JavaScript में कंपाइल करें.
firebase ext:dev:initकमांड की मदद से, अपने फ़ंक्शन लिखने के लिए TypeScript को चुना जा सकता है. इस कमांड से, आपको इंस्टॉल किया जा सकने वाला पूरा एक्सटेंशन के साथ-साथ एक बिल्ड स्क्रिप्ट भी मिलती है. इसेnpm run buildके साथ चलाया जा सकता है.अपनी
package.jsonफ़ाइल में, यह पक्का करें किmainफ़ील्ड, जनरेट की गई JavaScript की ओर इशारा कर रहा हो.अगर अपने एक्सटेंशन को लोकल सोर्स से इंस्टॉल या अपलोड किया जा रहा है, तो पहले अपनी TypeScript फ़ाइलें कंपाइल करें.
फ़ंक्शन के काम करने के लिए उपलब्ध ट्रिगर
एचटीटीपी ट्रिगर
एचटीटीपी से ट्रिगर होने वाला फ़ंक्शन, सार्वजनिक https एंडपॉइंट पर डिप्लॉय किया जाता है. साथ ही, एंडपॉइंट को ऐक्सेस करने पर यह काम करता है.
एचटीटीपी से ट्रिगर होने वाले फ़ंक्शन लिखने के बारे में जानकारी पाने के लिए, Cloud Functions documentation में Call functions via HTTP requests देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ पहली पीढ़ी के लिए)
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 दस्तावेज़ में अपने ऐप्लिकेशन से फ़ंक्शन कॉल करना देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ पहली पीढ़ी के लिए)
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 दस्तावेज़ में फ़ंक्शन शेड्यूल करना देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ पहली पीढ़ी के लिए)
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's TaskQueue.enqueue() तरीके का इस्तेमाल करके, आपके एक्सटेंशन के टास्क क्यू में मैन्युअल तरीके से जोड़ने पर भी ट्रिगर किया जा सकता है.
लाइफ़साइकल इवेंट को मैनेज करने वाले फ़ंक्शन लिखने के बारे में जानकारी पाने के लिए, अपने एक्सटेंशन के लाइफ़साइकल इवेंट मैनेज करना देखें.
टास्क क्यू फ़ंक्शन लिखने के बारे में जानकारी पाने के लिए, Cloud Functions दस्तावेज़ में Cloud Tasks के साथ फ़ंक्शन को क्यू में जोड़ना देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ पहली पीढ़ी के लिए)
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 के ट्रिगर देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ पहली पीढ़ी के लिए)
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 documentation में Firebase Authentication triggers देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ पहली पीढ़ी के लिए)
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 triggers देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ पहली पीढ़ी के लिए)
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 के ट्रिगर देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ पहली पीढ़ी के लिए)
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: ...
अगर आपको यह सुविधा देनी है कि उपयोगकर्ता आपका एक्स0/} विषय कॉन्फ़िगर कर सकें, तो अपनी extension.yaml फ़ाइल में एक नया पैरामीटर जोड़ें. साथ ही, अपने फ़ंक्शन की resource जानकारी में उस पैरामीटर का रेफ़रंस दें:Pub/Sub
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 के ट्रिगर देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ पहली पीढ़ी के लिए)
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 के ट्रिगर देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ पहली पीढ़ी के लिए)
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 के ट्रिगर देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ पहली पीढ़ी के लिए)
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 के ट्रिगर देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ पहली पीढ़ी के लिए)
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 के अलर्ट के ट्रिगर देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ दूसरी पीढ़ी के लिए)
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)
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.newFatalIssuecrashlytics.newNonfatalIssuecrashlytics.regressioncrashlytics.stabilityDigestcrashlytics.velocitycrashlytics.newAnrIssue
Performance Monitoring अलर्ट ट्रिगर
Performance Monitoring से ट्रिगर होने वाला फ़ंक्शन, Performance Monitoring के अलर्ट पब्लिश करने पर काम करता है.
अलर्ट से ट्रिगर होने वाले फ़ंक्शन लिखने के बारे में जानकारी पाने के लिए, Cloud Functions दस्तावेज़ में Firebase के अलर्ट के ट्रिगर देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ दूसरी पीढ़ी के लिए)
import { onThresholdAlertPublished } from "firebase-functions/v2/alerts/performance";
export const yourFunctionName = onThresholdAlertPublished((event) => {
// ...
});
संसाधन की जानकारी (extension.yaml)
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 के अलर्ट के ट्रिगर देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ दूसरी पीढ़ी के लिए)
import {
onNewTesterIosDevicePublished,
onInAppFeedbackPublished
} from "firebase-functions/v2/alerts/appDistribution";
export const yourFunctionName = onNewTesterIosDevicePublished((event) => {
// ...
});
export const yourFunctionName2 = onInAppFeedbackPublished((event) => {
// ...
});
संसाधन की जानकारी (extension.yaml)
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.newTesterIosDeviceappDistribution.inAppFeedback
कस्टम इवेंट ट्रिगर (Eventarc)
Eventarc से ट्रिगर होने वाला फ़ंक्शन, किसी खास चैनल पर किसी खास तरह का इवेंट पब्लिश होने पर काम करता है.
Eventarc से ट्रिगर होने वाले फ़ंक्शन लिखने के बारे में जानकारी पाने के लिए, Cloud Functions दस्तावेज़ में कस्टम इवेंट ट्रिगर बनाना और उन्हें मैनेज करना देखें.
आपके पास अपने एक्सटेंशन से इवेंट पब्लिश करने का विकल्प भी होता है. इससे, उपयोगकर्ताओं को अपने एक्सटेंशन में कस्टम लॉजिक जोड़ने का तरीका मिलता है. किसी एक्सटेंशन में, डेवलपर की ओर से दिए गए कस्टम लॉजिक का इस्तेमाल करना देखें.
फ़ंक्शन की परिभाषा (सिर्फ़ दूसरी पीढ़ी के लिए)
import { onCustomEventPublished } from "firebase-functions/v2/eventarc";
export const yourFunctionName = onCustomEventPublished((event) => {
// ...
});
संसाधन की जानकारी (extension.yaml)
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 इलाके में 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}