gpt4 book ai didi

firebase-cloud-messaging - 如何在firebase云函数中指定声音和click_action

转载 作者:行者123 更新时间:2023-12-03 23:27:57 34 4
gpt4 key购买 nike

我尝试使用以下功能(node.js v8):

exports.sendComNotification = functions.firestore
.document('Comunicados/{comID}')
.onUpdate((snap, context) => {
console.log('Com triggered');
const newValue = snap.after.data();
const msg = newValue.title;
var message = {
notification: {
title: 'Comunicado da Diretoria!',
body: msg,
badge: '1',
sound: 'default',
click_action: 'FLUTTER_NOTIFICATION_CLICK',
},
topic: "Comunicados"
};
return admin.messaging().send(message)
.then((response) => {
console.log('Successfully sent message:', response);
return
})
.catch((error) => {
console.log('Error sending message:', error);
return
});

});


但这会在 fucntions 日志中出现以下错误:

Error sending message: {
Error: Invalid JSON payload received.Unknown name "badge"
at 'message.notification': Cannot find field.
Invalid JSON payload received.Unknown name "sound"
at 'message.notification': Cannot find field.
Invalid JSON payload received.Unknown name "click_action"
at 'message.notification': Cannot find field.
at FirebaseMessagingError.FirebaseError[as constructor](/srv/node_modules / firebase - admin / lib / utils / error.js: 42: 28)


如果我取出“徽章”、“声音”和“click_action”,它会起作用,但是在接收时没有声音,并且 onResume(flutter 应用程序)中定义的 Action 当然也不会触发。设置声音和 click_action Prop 的正确方法是什么?提前致谢。

最佳答案

好的,我终于设法在这里和那里收集零碎的东西以使其工作。不明白为什么文档没有明确和直接的路径来满足这种常见的要求。

exports.sendComNotification = functions.firestore
.document('Comunicados/{comID}')
.onCreate((snap, context) => {
const doc = snap.data();
const msg = doc.title;
var message = {
notification: {
title: 'Comunicado da Diretoria!',
body: msg
},
data: {
title: 'Comunicado',
body: msg
},
android: {
notification: {
sound: 'default',
click_action: 'FLUTTER_NOTIFICATION_CLICK',
},
},
apns: {
payload: {
aps: {
badge: 1,
sound: 'default'
},
},
},
topic: "Comunicados"
};


return admin.messaging().send(message)
.then((response) => {

console.log('Successfully sent message:', response);
return
})
.catch((error) => {
console.log('Error sending message:', error);
return
});

});

关于firebase-cloud-messaging - 如何在firebase云函数中指定声音和click_action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59204040/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com