For Android push notifications in v2, Stream sends a simplified payload structure with only the FCM data field by default. The template functionality is limited to specific Firebase-supported fields:
The default data payload includes:
- - channel_id - the channel id
- - channel_type - the channel type
- - cid - the combination of channel channel type and channel id
- - message_id - the message id
- - receiver_id - the Stream user id who is receiving the PN
- - sender - the provider
- - type - type of event
- - version - the push notification system version
Example:
"data": {
"channel_id": "custom_field_event_test_01",
"channel_type": "messaging",
"cid": "messaging:custom_field_event_test_01",
"id": "agata-zPg-lXoE6yabQCK0XSUm0",
"message_id": "agata-zPg-lXoE6yabQCK0XSUm0",
"receiver_id": "sara",
"sender": "stream.chat",
"type": "message.new",
"version": "v2"
},
Once you add a template to the Stream dashboard, for example:
{
"title": "New message from WeaveTestPN pushprovider: {{ sender.name }} has messaging you!!",
"body": "{{ truncate message.text 2000 }}",
"click_action": "OPEN_ACTIVITY_1",
"sound": "default",
"notification_count": {{ unread_count }}
}
You will receive in the push notification payload both data and notification fields, for example:
{
"collapseKey": "com.rnstreamtutorial",
"data": {
"channel_id": "!members--YnBGG-YCLfT5ijpVGLjbQwm3sNwBaoubmfERy3R28M",
"channel_type": "messaging",
"cid": "messaging:!members--YnBGG-YCLfT5ijpVGLjbQwm3sNwBaoubmfERy3R28M",
"id": "agata-08AOFxh-PryoBPGZnYgqU",
"message_id": "agata-08AOFxh-PryoBPGZnYgqU",
"receiver_id": "Enrico",
"sender": "stream.chat",
"type": "message.new",
"version": "v2"
},
"from": "381439627273",
"messageId": "0:1730733019754925%7228e4e77228e4e7",
"notification": {
"android": {
"clickAction": "OPEN_ACTIVITY_1",
"count": 5,
"sound": "default"
},
"body": "new message push wav",
"title": "New message from WeaveTestPN pushprovider: agata has messaging you!!"
},
"sentTime": 1730733019745,
"ttl": 2419200
}
Note: Custom fields added directly to the Stream template will be ignored by FCM.
To include custom attributes (like user details or navigation parameters), you should:
1. Use the default data payload from Stream
2. Call the Stream API to retrieve additional information
3. Enrich the notification with custom attributes in your application logic when creating the local notification
Comments
0 comments
Please sign in to leave a comment.