firebase - Firebase 功能 + Firestore + 向多个令牌发送通知
问题描述
我创建了以下函数来向特定fcmToken发送通知
/**
* FOR ADMIN
*/
exports.adminNotification = functions.firestore.document('/pending_videos/{pushId}').onCreate(async (snap, context) => {
const newValue = snap.data();
const title = newValue.title;
const category = newValue.category;
const uploadedBy = newValue.uploadedBy;
// Grab the current value of what was written to the Realtime Database.
let adminRef = admin.firestore().collection('admin').doc('57MRzgiBwx2gO2JXZ4jo');
let token;
let getDoc = adminRef.get()
.then(doc => {
if (!doc.exists) {
console.log('No such document!');
} else {
console.log('Document data:', doc.data().url);
token = doc.data().token;
// Create a notification
const payload = {
data: {
title: "Jain Stavan Video Status",
body: title + " video uploaded in " + category + " category by " + uploadedBy + ".",
sound: "default"
},
};
//Create an options object that contains the time to live for the notification and the priority
const options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
console.log('Sending notification');
return admin.messaging().sendToDevice(token, payload, options);
}
})
.catch(err => {
console.log('Error getting document', err);
});
});
我已经使用静态文档.doc('57MRzgiBwx2gO2JXZ4jo')完成了它,但我想将它发送给所有管理员,这意味着管理员集合中的所有文档。
我怎样才能做到这一点?
解决方案
推荐阅读
- python - 如何在 django 中制作子页面 url
- wordpress - 如何添加“编辑评论”功能(WordPress)?
- c# - SQL 查询 - C# 中的执行时间慢,Toad 中的执行速度快
- php - 通过唯一链接 PHP 跟踪用户注册
- node.js - 正确地将 global.d.ts 导出到 npm 包中
- c# - 从和到字节数组的元帅类实例
- python - 为什么 YOLO 训练损失没有显着减少且平均 IoU 没有增加?
- firebase - Firebase 实时数据库:良好实践(过滤、排序等)
- python - ImportError:无法从“torch.nn.modules.loss”导入名称“_assert_no_grad”
- primefaces - 从 JSF2.0 迁移到 JSF 2.3 步骤