I am using node.js for cloud computing the notifications but the problem is that all the notifications are shown separately but I want them to be shown together like Instagram or WhatsApp. For example, A sends 3 messages to B then these three should be grouped together rather then showing three times.
But I want them to be like this i.e one notification for all:-
My Code:-
async function sendNotification(chatItem)
{
let body;
switch (chatItem.type)
{
case 0:
body = `${chatItem.senderUsername}: ${chatItem.message}`;
break;
case 1:
body = `${chatItem.senderUsername}: shared a photo`;
break;
case 2:
body = `${chatItem.senderUsername}: sent you a sticker`;
break;
case 3:
body = `${chatItem.senderUsername}: sent you a post`;
break;
case 4:
body = `${chatItem.senderUsername}: sent you a profile`;
break;
default:
break;
}
const message =
{
notification: {
title:'Message',
body: body,
imageUrl: url,
},
token: androidNotificationToken,
data: { recipient: senderUserId },
};
admin.messaging().send(message)
.then(response =>
{
console.log("Successfully sent message", response);
})
.catch(error =>
{
console.log("Error sending message", error);
})
}