【发布时间】:2020-07-12 11:34:49
【问题描述】:
我有 5000 多个用户令牌的 Firestore 文档,但 FCM 限制为 1000,我该如何发送 通知所有人。
如何使用循环发送 1000-1000 任何人都可以帮助我弄清楚这一点。
var newData;
exports.articlenotification = functions.firestore
.document("Articles/{id}")
.onCreate(async (snapshot, context) => {
//
if (snapshot.empty) {
console.log("No Devices");
return;
}
newData = snapshot.data();
const deviceIdTokens = await admin
.firestore()
.collection("Tokens")
.where("article", "==", true)
.get();
var tokens = [];
for (var token of deviceIdTokens.docs) {
tokens.push(token.data().token);
}
var payload = {
notification: {
title: "New Article",
body: newData.title,
image: newData.image,
sound: "default"
}
};
try {
const response = await admin.messaging().sendToDevice(tokens, payload);
console.log("Notification sent successfully");
} catch (err) {
console.log(err);
}
});
【问题讨论】:
标签: javascript node.js firebase firebase-cloud-messaging