javascriptfirebasegoogle-cloud-firestoregoogle-cloud-functionsgoogle-cloud-run

What does a triggering event for testing a (1st gen) Firestore triggered Cloud Function look like?


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:

Screenshot of Google Cloud console for Cloud Run functions

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?


Solution

  • 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: