সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
আপনি Firebase Remote Config ইভেন্টের প্রতিক্রিয়া হিসাবে একটি ফাংশন ট্রিগার করতে পারেন, যার মধ্যে একটি নতুন কনফিগার সংস্করণ প্রকাশ করা বা একটি পুরানো সংস্করণে রোলব্যাক রয়েছে৷ এই নির্দেশিকাটি বর্ণনা করে যে কীভাবে একটি Remote Config ব্যাকগ্রাউন্ড ফাংশন তৈরি করতে হয় যা দুটি টেমপ্লেট সংস্করণের একটি পার্থক্য সম্পাদন করে।
একটি Remote Config ফাংশন ট্রিগার করুন
একটি Remote Config ফাংশন ট্রিগার করতে, প্রথমে প্রয়োজনীয় মডিউলগুলি আমদানি করুন:
Node.js
// The Cloud Functions for Firebase SDK to set up triggers and logging.const{onConfigUpdated}=require("firebase-functions/v2/remoteConfig");constlogger=require("firebase-functions/logger");// The Firebase Admin SDK to obtain access tokens.constadmin=require("firebase-admin");constapp=admin.initializeApp();constfetch=require("node-fetch");constjsonDiff=require("json-diff");
# The Cloud Functions for Firebase SDK to set up triggers and logging.fromfirebase_functionsimportremote_config_fn# The Firebase Admin SDK to obtain access tokens.importfirebase_adminapp=firebase_admin.initialize_app()importdeepdiffimportrequests
তারপর আপডেট ইভেন্টের জন্য একটি হ্যান্ডলার সংজ্ঞায়িত করুন। এই ফাংশনে পাস করা ইভেন্ট অবজেক্টে একটি টেমপ্লেট আপডেট সম্পর্কে মেটাডেটা রয়েছে, যেমন আপডেটের নতুন সংস্করণ নম্বর এবং সময়। আপনি যে ব্যবহারকারীর জন্য আপডেট করেছেন তার ইমেলটি পুনরুদ্ধার করতে পারেন, যদি উপলব্ধ থাকে তবে নাম এবং একটি চিত্র সহ।
এখানে একটি Remote Config ফাংশনের একটি উদাহরণ রয়েছে যা প্রতিটি আপডেট হওয়া সংস্করণ এবং এটি প্রতিস্থাপিত সংস্করণের একটি পার্থক্য লগ করে। ফাংশনটি টেমপ্লেট অবজেক্টের সংস্করণ নম্বর ক্ষেত্রটি পরীক্ষা করে এবং বর্তমান (নতুন আপডেট হওয়া) সংস্করণটি একসংখ্যার নিম্ন সংস্করণের সাথে পুনরুদ্ধার করে:
Node.js
exports.showconfigdiff=onConfigUpdated(async(event)=>{try{// Obtain the access token from the Admin SDKconstaccessTokenObj=awaitadmin.credential.applicationDefault().getAccessToken();constaccessToken=accessTokenObj.access_token;// Get the version number from the event objectconstremoteConfigApi="https://firebaseremoteconfig.googleapis.com/v1/"+`projects/${app.options.projectId}/remoteConfig`;constcurrentVersion=event.data.versionNumber;constprevVersion=currentVersion-1;consttemplatePromises=[];templatePromises.push(fetch(remoteConfigApi,{method:"POST",body:newURLSearchParams([["versionNumber",currentVersion+""]]),headers:{Authorization:"Bearer "+accessToken},},));templatePromises.push(fetch(remoteConfigApi,{method:"POST",body:newURLSearchParams([["versionNumber",prevVersion+""]]),headers:{Authorization:"Bearer "+accessToken},},));// Get the templatesconstresponses=awaitPromise.all(templatePromises);constresults=responses.map((r)=>r.json());constcurrentTemplate=results[0];constpreviousTemplate=results[1];// Figure out the differences of the templatesconstdiff=jsonDiff.diffString(previousTemplate,currentTemplate);// Log the differencelogger.log(diff);}catch(error){logger.error(error);}});
এই নমুনাটি ডিফ তৈরি করতে এবং টেমপ্লেট অবজেক্ট পেতে অনুরোধ তৈরি করতে json-diff এবং request-promise মডিউল ব্যবহার করে।
পাইথন
@remote_config_fn.on_config_updated()defshowconfigdiff(event:remote_config_fn.CloudEvent[remote_config_fn.ConfigUpdateData])-> None:"""Log the diff of the most recent Remote Config template change."""# Obtain an access token from the Admin SDKaccess_token=app.credential.get_access_token().access_token# Get the version number from the event objectcurrent_version=int(event.data.version_number)# Figure out the differences between templatesremote_config_api=("https://firebaseremoteconfig.googleapis.com/v1/"f"projects/{app.project_id}/remoteConfig")current_template=requests.get(remote_config_api,params={"versionNumber":current_version},headers={"Authorization":f"Bearer {access_token}"})previous_template=requests.get(remote_config_api,params={"versionNumber":current_version-1},headers={"Authorization":f"Bearer {access_token}"})diff=deepdiff.DeepDiff(previous_template,current_template)# Log the differenceprint(diff.pretty())
[[["সহজে বোঝা যায়","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-06 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],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."]]