Closed manzoor-mt closed 5 years ago
I am trying to send a simple FCM notification to Android devices using sendToMultipleToken(). It always returns response like:
[{ "response": "Error sending message:", "token": "dc9x65gKLLo:APA91bFnku__06dRI7CHjaMLy1A9a4ixzu.........." }]
It's working fine, I checked, Can you please share your method to send?
I'am having exactly the same issue. When using method sendToMultipleToken() I got error message saying: "Error sending message:". I've noticed that Android tokens works, but for iOS token it wont send notification.
I installed the library with npm command and downloaded privatekey.json file using your link.
After that I created a function to send FCM i.e.
let FcmNotification = require('fcm-notification');
module.exports = class MyFCM {
constructor() {
this.fcm = new FcmNotification('privatekey.json');
}
sendFcm(message, fcmTokens) {
this.fcm.sendToMultipleToken(message, fcmTokens, (error, response) => {
if (error) {
console.log('Error # FCM failed => ', error);
}
else {
console.log('FCM response = ', response);
}
});
}
}
I called it like
// ....required MyFCM class here
let myFcm = new MyFCM();
myFcm.sendFcm({notification: {title: "test title", body: "this is a test"}}, ["eDzRC65Bu0E:APA91bEyblFMzpukUeBac2SgypdEwymlV63OtMwgzOR6DNCihIm1bEIFJpfZJlC6d1fPLPugeLZU0gWTR8Juijt0lVy3vNi4WbrwGa058EDaEMz1rvaQeIPKul0bJBsnlPPzQkBXPAuL"]);
These are the notification data I am sending to sendToMultipleToken()
const collapseKey = `chat.${msg.room_id}.message`;
const options = {
data: {
chat_room_id: `${msg.room_id}`
},
android: {
ttl: 24 * 60 * 60 * 1000,
priority: 'high',
collapseKey: collapseKey,
notification: {
title: msg.sender.name,
body: msg.content,
tag: collapseKey,
color: '#dd949b',
icon: 'notification_icon'
}
},
apns: {
headers: {
'apns-priority': '10',
'apns-collapse-id': collapseKey
},
payload: {
aps: {
alert: {
title: msg.sender.name,
body: msg.content
},
'thread-id': collapseKey
}
}
},
};
FCM.sendToMultipleToken(options, arrTokens, (err, response) => {
if (err) {
console.log("push error found", err);
} else {
console.log("push response here", response);
}
});
I've tested on Android device and notifications are working, but on iOS device wont send notifications.
I installed the library with npm command and downloaded privatekey.json file using your link.
After that I created a function to send FCM i.e.
let FcmNotification = require('fcm-notification'); module.exports = class MyFCM { constructor() { this.fcm = new FcmNotification('privatekey.json'); } sendFcm(message, fcmTokens) { this.fcm.sendToMultipleToken(message, fcmTokens, (error, response) => { if (error) { console.log('Error # FCM failed => ', error); } else { console.log('FCM response = ', response); } }); } }
I called it like
// ....required MyFCM class here let myFcm = new MyFCM(); myFcm.sendFcm({notification: {title: "test title", body: "this is a test"}}, ["eDzRC65Bu0E:APA91bEyblFMzpukUeBac2SgypdEwymlV63OtMwgzOR6DNCihIm1bEIFJpfZJlC6d1fPLPugeLZU0gWTR8Juijt0lVy3vNi4WbrwGa058EDaEMz1rvaQeIPKul0bJBsnlPPzQkBXPAuL"]);
Hi manzoor-mt , I have checked with this module with your given method, its working fine. You need to check your project setting under setting->General for android and ios.
I'm getting success response : response: 'Successfully sent message:projects/****' } ]
If any issue, please let me know.
Thanks, Navish
These are the notification data I am sending to sendToMultipleToken()
const collapseKey = `chat.${msg.room_id}.message`; const options = { data: { chat_room_id: `${msg.room_id}` }, android: { ttl: 24 * 60 * 60 * 1000, priority: 'high', collapseKey: collapseKey, notification: { title: msg.sender.name, body: msg.content, tag: collapseKey, color: '#dd949b', icon: 'notification_icon' } }, apns: { headers: { 'apns-priority': '10', 'apns-collapse-id': collapseKey }, payload: { aps: { alert: { title: msg.sender.name, body: msg.content }, 'thread-id': collapseKey } } }, }; FCM.sendToMultipleToken(options, arrTokens, (err, response) => { if (err) { console.log("push error found", err); } else { console.log("push response here", response); } });
I've tested on Android device and notifications are working, but on iOS device wont send notifications.
Hi tjodalv,
Please check your code from my end, it is working on ios from my end. var fcm = require('fcm-notification'); var FCM = new fcm('path.json'); const collapseKey = 'testcollapsKey';
const options = { data: { chat_room_id: 'roomId' }, android: { ttl: 24 60 60 * 1000, priority: 'high', collapseKey: collapseKey, notification: { title: 'Test title tjodalv', body: 'content for tjodalv', tag: collapseKey, color: '#dd949b', icon: 'notification_icon' } }, apns: { headers: { 'apns-priority': '10', 'apns-collapse-id': collapseKey }, payload: { aps: { alert: { title: 'Test title tjodalv', body: 'content for tjodalv' }, 'thread-id': collapseKey } } }, };
FCM.sendToMultipleToken(options, ['cOPEyz1QMPk:APA91bEe1uDq-qXczg-p0l9jvbCNlg1fLscpZQZnzYUoDmvKZlI-f630k**'],` (err, response) => { if (err) { console.log("push error found", err); } else { console.log("push response here", response); } });
Please check attached photo for reference.
If any issue then let me know.
Thanks, Navish
tjodalv
i get same error, the problem is : this package only can send 2 payload, that is title and body
I am trying to send a simple FCM notification to Android devices using sendToMultipleToken(). It always returns response like:
[{ "response": "Error sending message:", "token": "dc9x65gKLLo:APA91bFnku__06dRI7CHjaMLy1A9a4ixzu.........." }]