admin管理员组文章数量:1363337
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?
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?
Share Improve this question edited yesterday Alex Mamo 139k18 gold badges169 silver badges201 bronze badges Recognized by Google Cloud Collective asked 2 days ago Frank van PuffelenFrank van Puffelen 600k85 gold badges890 silver badges860 bronze badges Recognized by Google Cloud Collective1 Answer
Reset to default 2Here'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.
本文标签:
版权声明:本文标题:javascript - What does a triggering event for testing a (1st gen) Firestore triggered Cloud Function look like? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743817131a2544127.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论