새로운 구성 버전 게시 또는 이전 버전으로 롤백을 포함한 Remote Config 이벤트에 대한 응답으로 함수를 트리거할 수 있습니다.
이 가이드에서는 템플릿 버전 2개의 차이를 비교하는 Remote Config 백그라운드 함수를 만드는 방법을 설명합니다.
Remote Config 함수 트리거
Remote Config 이벤트의 핸들러를 정의하려면 functions.remoteConfig 모듈의 onUpdate() 함수를 사용합니다.
onUpdate에서 반환하는 TemplateVersion 객체에는 버전 번호와 업데이트 시간 같은 템플릿 업데이트의 핵심 메타데이터 필드가 포함되어 있습니다.
또한 업데이트한 사용자의 이메일을 이름 및 이미지(사용 가능한 경우)와 함께 검색할 수 있습니다.
다음은 업데이트된 각 버전과 대체된 버전의 차이를 반환하는 Remote Config 함수의 예시입니다. 이 함수는 템플릿 객체의 versionNumber 필드를 검사하여 새로 업데이트된 현재 버전과 함께 버전 번호가 하나 낮은 이전 버전을 검색합니다.
[null,null,["최종 업데이트: 2025-08-16(UTC)"],[],[],null,["\u003cbr /\u003e\n\n2nd gen 1st gen \n\n\u003cbr /\u003e\n\nYou can trigger a function in response to\nRemote 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 define a handler for Remote Config events, use the\n[`functions.remoteConfig`](/docs/reference/functions/firebase-functions.remoteconfig)\nmodule's `onUpdate()` function.\nThe `TemplateVersion` object returned by\n`onUpdate` contains the key metadata\nfields for a template update such as the 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\nreturns a diff of each updated version and the version it replaced. The function\nexamines the `versionNumber` field of the template object and retrieves the\ncurrent (newly updated) version together with the version one number lower: \n\n```gdscript\nexports.showConfigDiff = functions.remoteConfig.onUpdate(versionMetadata =\u003e {\n return admin.credential.applicationDefault().getAccessToken()\n .then(accessTokenObj =\u003e {\n return accessTokenObj.access_token;\n })\n .then(accessToken =\u003e {\n const currentVersion = versionMetadata.versionNumber;\n const templatePromises = [];\n templatePromises.push(getTemplate(currentVersion, accessToken));\n templatePromises.push(getTemplate(currentVersion - 1, accessToken));\n\n return Promise.all(templatePromises);\n })\n .then(results =\u003e {\n const currentTemplate = results[0];\n const previousTemplate = results[1];\n\n const diff = jsonDiff.diffString(previousTemplate, currentTemplate);\n\n functions.logger.log(diff);\n\n return null;\n }).catch(error =\u003e {\n functions.logger.error(error);\n return null;\n });\n});https://github.com/firebase/functions-samples/blob/c4fde45b65fab584715e786ce3264a6932d996ec/Node-1st-gen/remote-config-diff/functions/index.js#L25-L51\n```\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. For a sample\nthat incorporates Remote Config client logic as well as Firebase Cloud Messaging,\nsee [Propagate Remote Config updates in real time](/docs/remote-config/propagate-updates-realtime)."]]