عند إنشاء إضافة، تكتب منطقها باستخدام Cloud Functions، بالطريقة نفسها التي تكتب بها دالة سيتم استخدامها في مشروعك فقط. يمكنك تعريف الدوال في ملف extension.yaml
، وعندما يثبّت المستخدمون الإضافة، يتم نشر هذه الدوال في مشاريعهم.
راجِع مستندات Cloud Functions للحصول على معلومات عامة حول استخدام Cloud Functions.
الجيل الأول والثاني Cloud Functions
يتوافق Firebase مع كل من الجيل الأول والجيل الثاني Cloud Functions. ومع ذلك، تفرض Firebase Extensions حاليًا بعض القيود على الجيل الذي يمكنك استخدامه من الدوال السحابية مع أنواع معيّنة من المشغّلات. لهذا السبب، تتضمّن العديد من الإضافات مزيجًا من وظائف الجيل الأول والثاني.
يتم توضيح إمكانية إنشاء الدوال لكل نوع من أنواع المشغّلات أدناه.
اعتبارات خاصة
تتطلّب بعض تعريفات الدوال تحديد معلومات يتم تحديدها أيضًا في ملف
extension.yaml
. على سبيل المثال، يحتوي Cloud Firestore على طريقةdocument()
تحدّد نمط المستند الذي يجب مراقبته، ويتضمّن البيان المقابل فيextension.yaml
حقلresource
يحدّد النمط نفسه.في هذه الحالات، يتم استخدام الإعدادات المحدّدة في ملف
extension.yaml
ويتم تجاهل الإعدادات المحدّدة في تعريف الدالة.من الممارسات الشائعة تحديد القيمة التي تم ضبطها في تعريف الدالة بغض النظر عن ذلك، وذلك لأغراض التوثيق. وتتّبع الأمثلة الواردة في هذه الصفحة هذا النمط.
يتضمّن الجيل الأول من حزمة SDK الطريقتَين
functions.config()
وfunctions:config:set
، وهما أمران في واجهة سطر الأوامر يمكنك استخدامهما للتعامل مع القيم المحدّدة المَعلمات في دوال الجيل الأول.Cloud Functions تم إيقاف هذه التقنية نهائيًا في Cloud Functions، ولن تعمل على الإطلاق في أي إضافة. بدلاً من ذلك، استخدِم الوحدةfunctions.params
(ننصح بذلك) أوprocess.env
.
استخدام TypeScript
تصف معظم المستندات الخاصة بتطوير إضافتك سير العمل باستخدام JavaScript في Cloud Functions for Firebase. ومع ذلك، يمكنك بدلاً من ذلك كتابة الدوال باستخدام TypeScript.
في الواقع، تمت كتابة جميع الإضافات الرسميةFirebase باستخدام TypeScript. يمكنك مراجعة هذه الإضافات للتعرّف على بعض أفضل الممارسات لاستخدام TypeScript في إضافتك.
إذا كنت ستكتب وظائف الإضافة بلغة TypeScript، عليك تنفيذ ما يلي قبل تثبيت الإضافة:
جمِّع رمز مصدر دوال الإضافة إلى JavaScript.
يتيح لك الأمر
firebase ext:dev:init
اختيار TypeScript لكتابة الدوال. يوفّر لك الأمر إضافة كاملة قابلة للتثبيت بالإضافة إلى نص برمجي يمكنك تنفيذه باستخدامnpm run build
.في ملف
package.json
، احرص على توجيه الحقلmain
إلى رمز JavaScript الذي تم إنشاؤه.إذا كنت تثبّت الإضافة أو تحمّلها من مصدر محلي، عليك أولاً تجميع ملفات TypeScript.
مشغّلات الدوال المتوافقة
مشغّلات HTTP
يتم نشر دالة يتم تشغيلها بواسطة HTTP إلى نقطة نهاية https
عامة، ويتم تنفيذها عند الوصول إلى نقطة النهاية.
راجِع استدعاء الدوال من خلال طلبات HTTP في مستندات Cloud Functions للحصول على معلومات حول كتابة الدوال التي يتم تشغيلها بواسطة HTTP.
تعريف الدالة (الجيل الأول فقط)
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: ...
الدوال القابلة للاستدعاء
تشبه الدوال القابلة للاستدعاء الدوال التي يتم تشغيلها عبر HTTP، ولكنها تنفّذ بروتوكولاً يسهّل استدعاءها من الرمز البرمجي من جهة العميل.
راجِع استدعاء الدوال من تطبيقك في مستندات 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
عوامل تشغيل قائمة انتظار المهام
يتم تشغيل دالة قائمة انتظار المهام إما عند أحداث دورة الحياة في الإضافة أو عند إضافتها يدويًا إلى قائمة انتظار المهام في الإضافة باستخدام طريقة TaskQueue.enqueue()
في حزمة SDK الخاصة بالمشرف.
راجِع التعامل مع أحداث دورة حياة الإضافة للحصول على معلومات حول كتابة دوال تتعامل مع أحداث دورة الحياة.
راجِع وضع الدوال في قائمة الانتظار باستخدام Cloud Tasks في مستندات Cloud Functions للحصول على معلومات حول كتابة دوال قائمة انتظار المهام.
تعريف الدالة (الجيل الأول فقط)
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
يتم تشغيل دالة يتم تفعيلها من خلال "إحصاءات Google" عند تسجيل حدث محدّد في "إحصاءات Google".
راجِع مشغّلات "إحصاءات Google" في مستندات Cloud Functions للحصول على معلومات حول كتابة الدوال التي يتم تشغيلها من خلال "إحصاءات Google".
تعريف الدالة (الجيل الأول فقط)
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
يتم تشغيل دالة يتم تفعيلها عند المصادقة عند إنشاء مستخدم أو حذفه.
راجِع مشغّلات مصادقة Firebase في مستندات Cloud Functions للحصول على معلومات حول كتابة الدوال التي يتم تشغيلها عند المصادقة.
تعريف الدالة (الجيل الأول فقط)
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 عند إنشاء مستند أو تعديله أو حذفه.
راجِع مشغّلات Cloud Firestore في مستندات Cloud Functions للحصول على معلومات حول كتابة دوال يتم تشغيلها من خلال Firestore.
تعريف الدالة (الجيل الأول فقط)
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: ...
إذا أردت أن يتمكّن المستخدمون من ضبط موضوع 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 عندما يتم إنشاء مسار يطابق نمطًا محدّدًا أو تعديله أو حذفه.
راجِع مشغّلات Realtime Database في مستندات Cloud Functions للحصول على معلومات حول كتابة الدوال التي يتم تشغيلها بواسطة RTDB.
تعريف الدالة (الجيل الأول فقط)
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 للحصول على معلومات حول كتابة الدوال التي يتم تشغيلها من خلال "الإعداد عن بُعد".
تعريف الدالة (الجيل الأول فقط)
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 Storage في مستندات Cloud Functions للحصول على معلومات حول كتابة دوال يتم تشغيلها عند حدوث تغيير في 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
يتم تشغيل دالة تم تفعيلها من خلال "المختبر" عند انتهاء مصفوفة الاختبار من إجراء اختباراتها.
راجِع مشغّلات Firebase Test Lab في مستندات Cloud Functions للحصول على معلومات حول كتابة الدوال التي يتم تشغيلها من خلال 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 تنبيهًا.
راجِع مشغّلات تنبيهات Firebase في مستندات Cloud Functions للحصول على معلومات حول كتابة الدوال التي يتم تشغيلها عند تلقّي تنبيه.
تعريف الدالة (الجيل الثاني فقط)
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 تنبيهًا.
راجِع مشغّلات تنبيهات Firebase في مستندات Cloud Functions للحصول على معلومات حول كتابة الدوال التي يتم تشغيلها عند تلقّي تنبيه.
تعريف الدالة (الجيل الثاني فقط)
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 تنبيهًا.
راجِع مشغّلات تنبيهات Firebase في مستندات Cloud Functions للحصول على معلومات حول كتابة الدوال التي يتم تشغيلها عند تلقّي تنبيه.
تعريف الدالة (الجيل الثاني فقط)
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.
يمكنك أيضًا نشر أحداث من إضافاتك لمنح المستخدمين طريقة لإدراج منطق مخصّص في إضافتك. اطّلِع على استخدام منطق مخصّص يوفّره المطوّر في إحدى الإضافات.
تعريف الدالة (الجيل الثاني فقط)
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}