admin.messaging().sendToDevice(tokens, payload)这是有效载荷:
const payload = {
collapse_key: "something",
notification: {
body: message.body || "[ Sent you a photo ]",
},
data:{
"thread_id": String(thread_id),
"message_id": String(message_id),
"user_id": String(message.user_id),
"created_at": String(message.created_at),
}
};错误:消息传递有效负载包含无效的"collapse_key“属性。有效的属性是“数据”和“通知”。
为此我需要使用REST吗?如果是这样的话,那就太糟了,因为我得多付一些钱.
发布于 2017-09-12 23:12:56
collapseKey是MessagingOptions .You的一个属性,将选项作为sendToDevice()的第三个参数传递。
const options = {
priority: 'high',
collapseKey: 'myCollapseKey'
};
admin.messaging().sendToDevice(tokens, payload, options)
.then(function(response) {
console.log("Successfully sent message:", response);
})
.catch(function(error) {
console.log("Error sending message:", error);
});在文献资料中有一个完整的例子。
发布于 2021-11-03 12:29:18
对于那些使用最新的firebase-admin SDK和新的send()方法寻找更新解决方案的人,下面是我如何构建通知的方法:
{
"token": TARGET_DEVICE_FCM_TOKEN,
"notification": {
"title": "Notification title",
"body": "Optional body",
},
"android": {
"collapseKey": "YOUR_KEY",
}
...rest of payload
}来源:包装类型
https://stackoverflow.com/questions/46186330
复制相似问题