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 API?如果是这样,那真的很糟糕,因为我必须为传出请求支付额外费用......
答案 0 :(得分:4)
collapseKey
是MessagingOptions的属性。您将选项作为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);
});
完整的示例位于the documentation。