I'm using FCM for a chat app. Everytime an user receives a message, I send him a notification via FCM. If user isn't with my web app in foreground, the message handling happens in a default Service Worker that generates a notification with the parameters I've specified on the body of my request. The problem is, everytime a new push message is sent and the app is in background, browsers (tested on Chrome and Firefox) are creating a new message instead of updating the existing one. I would like to keep the already visible notification and only update its value, is that possible?
importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-messaging.js');
firebase.initializeApp({
'messagingSenderId': '*****'
});
const messaging = firebase.messaging();
{
"priority" : "normal",
"collapse_key": "demo",
"notification": {
"title": "Felicius Humble",
"body": "This is a sample message content",
"click_action": "https://****.herokuapp.com",
"icon": "****"
},
"to": "****",
"data": {
"id": 7,
"timestamp": 1493573846692,
"content": "teste",
"type": "MESSAGE",
"direction": "OUTPUT",
"sender": {
"id": 5,
"name": "Felicius Humble",
"email": "****@gmail.com",
"gender": "MALE",
"picture": "****",
"facebookID": "****",
"fcmToken": "****",
"accessToken": "****"
},
"chatID": 3
}
}
Ok, so I've found this that shows all options available for the json body. For what I need I just need to add "tag" param on notification obj in my json body. If you want to update the notification, sent it with the same tag. Example:
{
"notification": {
"title": "",
"body": "",
"click_action": "",
"icon": "",
"tag" : "this must be the same for the notifications you want to update"
},
"to": "****",
"data": {}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With