Open acalatrava opened 7 years ago
On your server side :
let message = {
to: token,
notification: {
tag: "new_messages",
title: `You have ${count} new message${count == 1 ? '' : 's'}`,
body: 'Click to read them!',
sound: 'default',
//badge: "100"
},
data: {
type: "chat"
},
collapse_key: "new_messages"
};
Example from @jonathan-chin
I have the same problem too. COLLAPSE_KEY is not working ?
Do we need to add something to the code ?
@Krypternite from my example code above,
You need collapse_key: "new_messages" and notification: { tag: "new_messages" }
It works
@ostrichegret , I've tried using collapse_key
and it doesn't work, if I use tag
it only works for Android and Browser.
@ostrichegret your example works for me.
I also tried to use different callapse_key values (based on the type of messages) and it didn't worked. That might be due that i converted integers to strings and used them as the keys. That is my finding.
@truca , collapse_key
is meant to work when the device is offline, and when regains internet connection it will only deliver the last notification received while offline.
https://firebase.google.com/docs/cloud-messaging/concept-options
@nickmendes I don't know about the offline device, are you using local notification? I haven't test it.
What I know about collapse_key is, it will help to replace the old notification that i sent from online server to new one. Without collapse_key, it will flood the device notification up to 100 notification before it get discarded ( this most likely happen on chat app ).
@truca maybe it's still in interger and fcm only accept strings, try to debug the value type.
<?php
$interger = 888;
echo gettype ( $interger );
echo "<br/>";
$string = "" . $interger;
echo gettype ( $string );
?>
The @ostrichegret solution worked for me:
(Collapsing only the identical messages)
var collapseKey = 'I am the fucking collapse key';
var message = {
to: 'the_token',
time_to_live: 60 * 60 * 24, //one day
collapse_key: collapseKey,
delay_while_idle: false,
data: {
payload: { someUtilData: 'very usefull' },
},
notification: {
title: 'Hello motherfucker',
body: 'Nice body',
tag: collapseKey,
icon: 'ic_notification',
color: '#18d821',
sound: 'default',
},
};
@Krypternite from my example code above,
You need collapse_key: "new_messages" and notification: { tag: "new_messages" }
It works
Your are awesome
none of the above solutions have worked for me. Anyone know what I'm doing wrong? (These notifications are going to an iOS front end)
Expected behavior:
I'm expecting any notification with the same collapseId
to be replaced by the most recent one sent
What actually happens: They all just send as new notifications
// send notifications
var FCM = require('fcm-push');
var serverKey = creds.firebase.serverKey;
var fcm = new FCM(serverKey);
let message = {
to: token,
collapse_key: collapseId,
notification: {
title: title,
body: body,
},
}
fcm.send(message, function(err, response) {
let data = JSON.parse(response || "{}") || {}
console.log("resp", data)
let isSuccess = data.success || 0
console.log("Sending notification: " + isSuccess)
})
@Krypternite from my example code above, You need collapse_key: "new_messages" and notification: { tag: "new_messages" } It works
Your are awesome
its not working can u plz share your payload
After using your plugin I noticed that the notifications won't collapse even if I add the collapse_key as per FCM docs (https://firebase.google.com/docs/cloud-messaging/http-server-ref)
Is there something that I may need to add to the code so it will work?
Thanks