如果我只想向角色为A的用户发送通知,我需要使用令牌吗?
下面是我的代码index.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.notifyDoctorregisTopic = functions.firestore.document('clinicreport/{reportId}')
.onCreate(async (snapshot, context) => {
const data = snapshot.data();
// Check the conditions
if (data.uid !== null && data.status === 'waiting') {
const payload = {
notification: {
title: 'มีClinicสมัครมา',
body: 'A new clinic report is available',
clickAction: 'FLUTTER_NOTIFICATION_CLICK',
},
data: {
click_action: 'FLUTTER_NOTIFICATION_CLICK', // for background
}
};
// Send the notification to the Doctorregis topic
return admin.messaging().sendToTopic('Doctorregis', payload);
}
return null;
});
字符串
我尝试这个代码,它发送通知给所有用户。
1条答案
按热度按时间rggaifut1#
主题消息将发送给订阅了某个主题的所有用户。
主题消息传递允许您将消息发送到选择了特定主题的多个设备。您可以根据需要编写主题消息,FCM会处理消息的路由并将其可靠地传递到正确的设备。
订阅
字符串
发送
型
详情请参见Topic messaging on Flutter。