با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
میتوانید عملکردی را در پاسخ به رویدادهای Firebase Remote Config ، از جمله انتشار نسخه پیکربندی جدید یا بازگشت به نسخه قدیمیتر، فعال کنید. این راهنما نحوه ایجاد یک تابع پس زمینه Remote Config را توضیح می دهد که تفاوت دو نسخه الگو را انجام می دهد.
یک تابع Remote Config را فعال کنید
برای تعریف یک کنترل کننده برای رویدادهای Remote Config ، از تابع onUpdate() ماژول functions.remoteConfig استفاده کنید. شی TemplateVersion برگردانده شده توسط onUpdate حاوی فیلدهای ابرداده کلیدی برای به روز رسانی الگو است، مانند شماره نسخه و زمان به روز رسانی. همچنین میتوانید ایمیل کاربری که بهروزرسانی را انجام داده است، با نام و تصویر در صورت وجود، بازیابی کنید.
در اینجا مثالی از یک تابع Remote Config است که تفاوت هر نسخه به روز شده و نسخه جایگزین شده را برمی گرداند. این تابع فیلد versionNumber شی الگو را بررسی می کند و نسخه فعلی (تازه به روز شده) را به همراه نسخه یک عدد پایین تر بازیابی می کند:
تاریخ آخرین بهروزرسانی 2025-09-04 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-09-04 بهوقت ساعت هماهنگ جهانی."],[],[],null,["\u003cbr /\u003e\n\nYou can trigger a function in response to\n[Firebase Remote Config](/docs/remote-config) events, including\nthe publication of a new config version or the rollback to an older version.\nThis guide describes how to create a Remote Config background function\nthat performs a diff of two template versions.\n\nTrigger a Remote Config function\n\nTo trigger a Remote Config function, first import the\nrequired modules: \n\nNode.js \n\n // The Cloud Functions for Firebase SDK to set up triggers and logging.\n const {onConfigUpdated} = require(\"firebase-functions/v2/remoteConfig\");\n const logger = require(\"firebase-functions/logger\");\n // The Firebase Admin SDK to obtain access tokens.\n const admin = require(\"firebase-admin\");\n const app = admin.initializeApp();\n const fetch = require(\"node-fetch\");\n const jsonDiff = require(\"json-diff\"); \n https://github.com/firebase/functions-samples/blob/c4fde45b65fab584715e786ce3264a6932d996ec/Node/remote-config-diff/functions/index.js#L20-L27\n\nPython \n\n # The Cloud Functions for Firebase SDK to set up triggers and logging.\n from firebase_functions import remote_config_fn\n\n # The Firebase Admin SDK to obtain access tokens.\n import firebase_admin\n\n app = firebase_admin.initialize_app()\n\n import deepdiff\n import requests \n https://github.com/firebase/functions-samples/blob/c4fde45b65fab584715e786ce3264a6932d996ec/Python/remote-config-diff/functions/main.py#L17-L26\n\nThen define a handler for the update event. The event object passed to\nthis function contains metadata\nabout a template update, such as the new version number and time of the update.\nYou can also retrieve the email for the user who made the update, with name\nand an image if available.\n\nHere's an example of a Remote Config function that\nlogs a diff of each updated version and the version it replaced. The function\nexamines the version number field of the template object and retrieves the\ncurrent (newly updated) version together with the version one number lower: \n\nNode.js \n\n exports.showconfigdiff = onConfigUpdated(async (event) =\u003e {\n try {\n // Obtain the access token from the Admin SDK\n const accessTokenObj = await admin.credential.applicationDefault()\n .getAccessToken();\n const accessToken = accessTokenObj.access_token;\n\n // Get the version number from the event object\n const remoteConfigApi = \"https://firebaseremoteconfig.googleapis.com/v1/\" +\n `projects/${app.options.projectId}/remoteConfig`;\n const currentVersion = event.data.versionNumber;\n const prevVersion = currentVersion - 1;\n const templatePromises = [];\n templatePromises.push(fetch(\n remoteConfigApi,\n {\n method: \"POST\",\n body: new URLSearchParams([[\"versionNumber\", currentVersion + \"\"]]),\n headers: {Authorization: \"Bearer \" + accessToken},\n },\n ));\n templatePromises.push(fetch(\n remoteConfigApi,\n {\n method: \"POST\",\n body: new URLSearchParams([[\"versionNumber\", prevVersion + \"\"]]),\n headers: {Authorization: \"Bearer \" + accessToken},\n },\n ));\n\n // Get the templates\n const responses = await Promise.all(templatePromises);\n const results = responses.map((r) =\u003e r.json());\n const currentTemplate = results[0];\n const previousTemplate = results[1];\n // Figure out the differences of the templates\n const diff = jsonDiff.diffString(previousTemplate, currentTemplate);\n // Log the difference\n logger.log(diff);\n } catch (error) {\n logger.error(error);\n }\n }); \n https://github.com/firebase/functions-samples/blob/c4fde45b65fab584715e786ce3264a6932d996ec/Node/remote-config-diff/functions/index.js#L31-L73\n\nThis sample uses the [`json-diff`](https://www.npmjs.com/package/json-diff) and\n[`request-promise`](https://www.npmjs.com/package/request-promise) modules to\ncreate the diff and build the request to get the template object.\n\nPython \n\n @remote_config_fn.on_config_updated()\n def showconfigdiff(event: remote_config_fn.CloudEvent[remote_config_fn.ConfigUpdateData]) -\u003e None:\n \"\"\"Log the diff of the most recent Remote Config template change.\"\"\"\n\n # Obtain an access token from the Admin SDK\n access_token = app.credential.get_access_token().access_token\n\n # Get the version number from the event object\n current_version = int(event.data.version_number)\n\n # Figure out the differences between templates\n remote_config_api = (\"https://firebaseremoteconfig.googleapis.com/v1/\"\n f\"projects/{app.project_id}/remoteConfig\")\n current_template = requests.get(remote_config_api,\n params={\"versionNumber\": current_version},\n headers={\"Authorization\": f\"Bearer {access_token}\"})\n previous_template = requests.get(remote_config_api,\n params={\"versionNumber\": current_version - 1},\n headers={\"Authorization\": f\"Bearer {access_token}\"})\n diff = deepdiff.DeepDiff(previous_template, current_template)\n\n # Log the difference\n print(diff.pretty()) \n https://github.com/firebase/functions-samples/blob/c4fde45b65fab584715e786ce3264a6932d996ec/Python/remote-config-diff/functions/main.py#L31-L53\n\nThis sample uses [`deepdiff`](https://pypi.org/project/deepdiff/) to\ncreate the diff, and `requests` to build and send the request to get\nthe template object."]]