Skip to content

Instantly share code, notes, and snippets.

@maxirosson
Last active September 29, 2021 18:29
Show Gist options
  • Save maxirosson/2ba20f3c06bd9a6e3d2e656e009bf4e1 to your computer and use it in GitHub Desktop.
Save maxirosson/2ba20f3c06bd9a6e3d2e656e009bf4e1 to your computer and use it in GitHub Desktop.
Firebase Cloud Function to send an FCM ping on Remote Config events
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.pushConfig = functions.remoteConfig.onUpdate((versionMetadata) => {
// Create FCM payload to send data message to REMOTE_CONFIG_PUSH topic.
const payload = {
topic: "REMOTE_CONFIG_PUSH",
data: {
"REMOTE_CONFIG_STATUS": "STALE",
},
fcm_options: {
"analytics_label": "REMOTE_CONFIG_PUSH",
},
};
// Use the Admin SDK to send the ping via FCM.
return admin.messaging().send(payload).then((resp) => {
console.log(resp);
return null;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment