如何为推送通知有效负载添加通道id



我使用推送通知与本地通知。我必须在我的有效载荷中设置通道id。这是我的有效载荷

我不确定这是否是android和ios的有效载荷。请帮我找出正确的有效载荷。

感谢
exports.chatFunctions = functions.firestore.document("chat/{chatId}/Messages/{messagesId}").onCreate(async (snapshot, context) => {
if (!snapshot.exists) {
console.log('No Device');
}
const chatDatas = snapshot.data();
const messageTo = chatDatas['idTo'];
const deviceTokenuUser1 = await admin.firestore().collection('users').doc(messageTo).get();
const user1name = deviceTokenuUser1.data()['name'];
const user1Url = deviceTokenuUser1.data()['profilePictureUrl'];
let payload = {
notification: {
title: `${user1name}`,
body: `${chatDatas['content']}`,
},
data: {
key: 'chat',
id: `${messageTo}`,
click_action: "FLUTTER_NOTIFICATION_CLICK"
},
android: {
priority: "high",
},
apns: {
payload: {
aps: {
contentAvailable: true,
},
},
headers: {
"apns-push-type": "background",
"apns-priority": "5", // Must be `5` when `contentAvailable` is set to true.
"apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
},
},
token: deviceTokenuUser1.data()['tokens'],
};
try {
await admin.messaging().send(payload);
console.log("Firebase chat Messaging Successfully");
} catch (err) {
console.log("error from chat messaging " + err);
}

您可以像这样添加频道id:

let payload = {
// ...
android: {
priority: "high",
notification: {
channelId: "yourchannelid"
}
}
// ...
}

最新更新