I have a (1st gen) Cloud (Run) Function that is triggered by a document being created in Firestore. I want to test this function with the TESTING functionality that is built into the Google Cloud console:
This requires that I enter JSON in the Configure Triggering Event box, but I can't find anywhere what this JSON should look like.
In case it matters, this is what my Cloud Function looks like (its one of the ones that FlutterFlow comes with):
exports.sendUserPushNotificationsTrigger = functions
.runWith(kPushNotificationRuntimeOpts)
.firestore.document(`${kUserPushNotificationsCollection}/{id}`)
.onCreate(async (snapshot, _) => {
try {
// Ignore scheduled push notifications on create
const scheduledTime = snapshot.data().scheduled_time || "";
if (scheduledTime) {
return;
}
// Don't let user-triggered notifications to be sent to all users.
const userRefsStr = snapshot.data().user_refs || "";
if (userRefsStr) {
await sendPushNotifications(snapshot);
}
} catch (e) {
console.log(`Error: ${e}`);
await snapshot.ref.update({ status: "failed", error: `${e}` });
}
});
Does anyone have an example of the JSON for Configure Triggering Event for this Cloud Function?
Here's an example of the JSON that can be used to trigger the sendUserPushNotificationsTrigger
function in the question:
{
"value": {
"name": "projects/nanochat-20241022-mw8qu9/databases/(default)/documents/ff_user_push_notifications/fM282xjEJjTXshxK7mhs",
"fields": {
"scheduled_time": { "stringValue": "" },
"initial_page_name": { "stringValue": "" },
"notification_title": { "stringValue": "Your friends are missing you!" },
"notification_text": { "stringValue": "Please come back to Nanochat" },
"user_refs": {
"stringValue": "users/VXu6EvFMl5M8KMXriYRvFEWTFHA2"
}
}
}
}
In here:
name
is the path to the document that triggered the function. This document must already exist. In here:
nanochat-20241022-mw8qu9
is the project ID that contains the Firestore database.ff_user_push_notifications
is the collection to which a document was added.fM282xjEJjTXshxK7mhs
is the ID of the triggering document.fields
are the fields in the document, in typical gRPC/protobuf format. The exact fields of course depend on what your Cloud Function code uses, so you'll need to update this.