novu
novu copied to clipboard
🚀/🐛 Feature/Bug: No possibility of sending FCM data payload
🔖 Feature description
Dear all
With the commit 8c30377ddd806d4c06d51ba4f9ee6541ab593e38
there was the introduction of the new FCM API, where novu uses now sendMulticast
.
I'd like to send some payload data to handle clicks on push notifications, i.e. I want to use the data
property for a received push notification.
In fcm.provider.ts
, there's this:
async sendMessage(
options: IPushOptions
): Promise<ISendMessageSuccessResponse> {
delete (options.overrides as any)?.deviceTokens;
const res = await this.messaging.sendMulticast({
tokens: options.target,
notification: {
title: options.title,
body: options.content,
...options.overrides,
},
});
So, Novu only uses the notification
property of the MulticastMessage
, which is an extension of the a BaseMessage. The BaseMessage
also allows for a data
property, which then can be accessed when the notification is received.
Be aware, that just using payload
as the data
property might be an issue, since payload can be of any type, e.g. payload : { someList : [] }
would fail, because the data
property must be { [key: string]: string; }
according to the docs.
Now, I would do and push this feature myself but sadly I'm not experienced enough with JS to build the application...
Thanks!
🎤 Why is this feature needed ?
To act according to the received data when clicking on a received FCM push notification, e.g. show a different screen than usual etc.
✌️ How do you aim to achieve this?
See above.
🔄️ Additional Information
No response
👀 Have you spent some time to check if this feature request has been raised before?
- [X] I checked and didn't find similar issue
🏢 Have you read the Code of Conduct?
- [X] I have read the Contributing Guidelines
Are you willing to submit PR?
None
@scopsy I'd like to work on this issue if possible
@LetItRock
I have the same issue In some case, My app don't send title and message, it only sends data for mobile device
The web UI of Novu always requires these values
--
Update, we can add any text to the required field
Change notification type to data
, any data in payload will convert to fcm data mesage
novu.trigger("template-name", {
to: {
subscriberId: subscriberId,
},
payload: {
some_data_key: "some value",
sound: "tadah_20s.wav"
},
overrides: {
fcm: {
type: "data"
},
},
})
I think the document is missing this part