Group notifications with Expo - react-native

I have a react native messaging app done with Expo. I got notifications to work, but the problem is that each message is a separate notification.
I would like to group notifications sent by the same person. Currently, I have:
[Notification]
John - Hey, how are you?
[Notification]
John - Long time no see!
and I would like them to merge as a single one when the second message is received, like this:
[Notification]
John |
Hey, how are you?
Long time to see!
I might be missing something because I cannot find anyone else wondering about such a common functionality.
The code I use to send notifications from my backend (python):
headers = {
'Accept': 'application/json',
'Accept-encoding': 'gzip, deflate',
'Content-Type': 'application/json',
}
session.post(
"https://exp.host/--/api/v2/push/send",
json = {
"to": expo_token,
"title": username,
"body": message_content,
},
headers=headers
)

In iOS you should use apns-collapse-id
https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns
An identifier you use to coalesce multiple notifications into a single
notification for the user. Typically, each notification request causes
a new notification to be displayed on the user’s device. When sending
the same notification more than once, use the same value in this
header to coalesce the requests. The value of this key must not exceed
64 bytes.
Update
For using collapse feature, you can use for Notifications other service. Which supports collapse and react native - for example
https://documentation.onesignal.com/docs/how-notifications-work#section-notification-collapsing

It seems like you can not control how notifications group in Expo app now, but I noticed that on IOS they are being grouped together automatically, while on Android you need to set notification.androidMode to collapse.
Take a look at current documentation: https://docs.expo.dev/versions/latest/config/app/#androidmode
app.json
Path: notification.androidMode
Type: enum
Show each push notification individually (default) or collapse into one (collapse).
All your messages will still be separate notifications, but at least they will collapse into one (stack).
That will only work in standalone app, nor in Expo Go.

Related

Cannot register device with TalkJs for push notifications

I am working on a React Native app that uses TalkJS. We want users to get a push notification for every message they receive. The messages are going through but we aren't getting notifications. We have uploaded our .p12 to the TalkJS dashboard and followed the docs for setting up a React Native project. Below is the relevant code we're injecting to the TalkUI loadScript. We followed https://talkjs.com/docs/Features/Notifications/Mobile_Push_Notifications.html
const res = await window.talkSession.registerDevice({ platform: "ios", pushRegistrationId: "${deviceToken}"});
alert("registering deviceToken ${deviceToken} response: " + res)
We are getting the alert with the correct deviceToken but this method does not return anything. We tried .then and an error first callback but nothing is coming back from this method.
Edit: this method is not designed to return anything, so the response is expected to be empty.
The Promise was designed to not return anything as Kapobajza mentioned.
From their support chat: "We have an issue regarding push notifications on iOS when using React Native."
Edit: this issue has been resolved. In addition to work that needed to be done by the TalkJS team, push notifications require a user to have a 'role', as is very loosely implied in the Overview for Push Notifications

Can I modify expo push notification title/body before showing the notification?

I'm using expo notification service.
I would like to send keys from backend, e.g.
{
title: "TITLE_KEY",
body: "BODY_KEY"
}
then translate it when it comes on the mobile side (based on the key), before showing it, so user would not see the key on notification, just the translated text...
So the question is how could I modify notification before showing it to the user?

Send push notification to people within a x-meter radius with OneSignal

I have a OneSignal account.
I have a front-end PWA built with VueJs that collects users & sends there location in a tag.
OneSignal.push(function() {
OneSignal.sendTags({
latitude: latitude,
long: longitude
})
})
I have successfully sent push messages from the API, when addressing all or a specific segment.
My problem is when using the location filter.
I have tried with this Json :
{"app_id": "APIKEY","contents": {"en": "English Message"},"filters": [{"field": "location", "radius": "1000", "lat": "50.747164", "long": "3.345545"}]}
I realise it's counter intuitive to send latitude and expect to filter on lat... but this is what i found in the documentation. Also some things made me think 'location' is a field of its own, not part of the tag. But I could not find this field when creating a segment manualy. So I've hit a dead end here.
If I should use a different platform, or a whole different approach, I'm open to that. Currently I'm stuck with no extra info.
register for native devices on OneSignal.
If this is happening to you you are possibly not registered on native platforms.
Check in your One-signal under settings if you have registered native devices.
Location based sending only works with native device setup.
If 'location' is not under segment then it is just not active.

Change sound in expo.sendPushNotificationsAsync

I want to play some other sound when hitting any notification in my expo app from node server.I can't find any other sound than 'default'.Is there any other option I can use to play some other sound other than the default one on notifications in expo.My nodeJS code is below:
const receipts = expo.sendPushNotificationsAsync([
{
to: userObj.pushToken,
sound: 'default',
body: notification,
data: { withSome: notification },
priority: 'high',
},
]);
I looked up in the Message Format section of the docs and found this :
A sound to play when the recipient receives this notification. Specify
"default" to play the device's default notification sound, or omit this
field to play no sound.
Note that on apps that target Android 8.0+ (if using `expo build`, built
in June 2018 or later), this setting will have no effect on Android.
Instead, use `channelId` and a channel with the desired setting.
sound?: 'default' | null,
Looks like it is not possible to change sound through app.

GCM 3.0 - send notification paylod to iOS and data payload to Android?

I would like to use the notification payload for iOS notifications (not Android), and the data payload for Android.
Is this possible? I am worried by using the notification payload for iOS, the Android notification will ben generated automatically.
With a single topic, if you want to deliver a push via notification payload on iOS, but via data payload on Android, you can't!
For example, if you have a topic called "awesome_news" you should split this into two topics: "awesome_news_ios" and "awesome_news_android"