question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to merge multiple notifications on tray into one?

See original GitHub issue

I’m sending push notifications with axios from one device to another through fcm server. I can receive the notification. As I’m working on a chat app, each time I press _onSendMessage, i’ll do a post request to fcm server. Each time I’ll be sending multiple individual notifications and ended up flooding my notification tray with 4-8 separate notifications from the same app.

How do I merge all of them together? I looked up and seems like we need to use collapse_key. Here’s my code for sending the pushes, which I included the collapse_key but it isn’t merging.

const config = { headers: { 'Content-Type': 'application/json', 'Authorization': 'key=myAPIKey' } }; const content = JSON.stringify({ to: deviceToken, collapse_key: "replace", data: { 'title' : 'You have new messages!', 'color' : 'red', 'message' : 'Someone has sent you a message!', }; }); Axios.post('https://fcm.googleapis.com/fcm/send', content, config);

Is it because collapse_key is not supported in this version or i’m writing something wrong? Thanks in advance!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:9

github_iconTop GitHub Comments

3reactions
fufuninjacommented, Aug 9, 2017

if anyone is still looking for a solution or alternatives, try react-native-one-signal which also supports grouping.

Just send a POST request that looks something like this: const config = { headers: { 'Content-Type': 'application/json', 'Authorization': 'Basic <Your Key>' } }; const body = JSON.stringify({ "app_id": <your app id>, "include_player_ids": <users u want to notify>, "contents": {"en": "Hello"}, "android_group": "stack", "priority": 10 }); Axios.post('https://onesignal.com/api/v1/notifications', body, config);

It will automatically combine notifications with the same android_group, therefore becoming one single notification that displays the content of all other notifications of its android_group( like WhatsApp’s 1 to 1 chat notification when you receive more than two lines of messages.)

As for collapsing all notifications of the same android_group into one single notification that shows the latest notification, I have yet to find a solution.

1reaction
peacechencommented, Oct 23, 2018

I’ve experimented with silent notifications. The idea is to intercept the silent notification in the app, then create a local notification in an attempt to collapse them.

I’ve tried calling PushNotification.cancelLocalNotifications({id}) as per the documentation, but it doesn’t remove the notification from the notification center.

Separately the documentation at https://github.com/zo0r/react-native-push-notification#2-cancelalllocalnotifications says NOTE: there is currently no api for removing specific notification alerts from the notification centre.

It’s not clear whether that statement is referring to iOS, Android or both.

I think this needs to be a change on the native side. iOS APN has the field apns-collapse-id https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to merge multiple notifications on tray into one?
I'm sending push notifications with axios from one device to another through fcm server. I can receive the notification.
Read more >
Consolidate Your Notifications and Alerts with a Single ...
Here's how to consolidate all your notifications into one unified, ... when you're bombarded with notifications from many different places.
Read more >
Customize the taskbar notification area - Microsoft Support
To hide an icon in the taskbar corner overflow. Press and hold or right-click any empty space on the taskbar and select Taskbar...
Read more >
Multiple change in one submit, trigger a bunch of - ServiceNow
Multiple change in one submit, trigger a bunch of notification, can them be merged into one? Go to solution. Rock Huang. Kilo Contributor....
Read more >
Merge multiple fcm Notification in ionic 3 - Stack Overflow
I have created an application in ionic. The application receives notification and is working well. However, when i send more notification to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found