I want to send a push notification to a specific android notification channel, as described here:
https://developer.android.com/guide/topics/ui/notifiers/notifications.html#ManageChannels
Error: Invalid JSON payload received. Unknown name "android_channel_id" when calling admin.messaging ().send () with the following payload
let pushMessage = {
notification: {
title: title,
body: body,
},
android: {
"notification": {
"title": title,
"body": body,
"sound": "mysound",
"tag": "alerts",
"icon": "myicon",
"android_channel_id": "myalertchannel",
}
}
I've tried putting android_channel_id in several different objects of the payload and received the same error. I know that channels are supported because you can set the channel in the firebase console and I've confirmed my phone receive the notification. Am I missing something?
This is not supported in the backend REST API: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#AndroidConfig
SDK cannot support it until it's exposed in the REST interface. I have an internal bug tracking this request with the FCM team.
So what is the official way now to go about sending messages via node admin SDK now then?
We need to target API Level 26 and from what I understand, for notifications to be displayed, they need a set channel. Does anyone here have this working? How do I set the channel? Do I need to pin to an older version of the SDK that still allowed arbitrary keys (as suggested here)? Or what's the best way to make this work for now?
@hiranya911 are there any updates on the channel id? It looks like the legacy api has support for the channel_id(https://firebase.google.com/docs/cloud-messaging/http-server-ref), any reason why the new api doesn't?
I'd love a solution to this. We are using admin.messaging.sendToDevice and from what I can see we don't have a way to set a channel.
@skabber if you're using sendToDevice and set android_channel_id it works
Thanks @rstims android_channel_id does work when putting it in the notification part of the payload. I wonder why iOS payload doesn't support thread-id.
@hiranya911 Any internal updates?
This has been implemented. Will be included in the next release.
Can you please send the payload format for the notification channel.
Thanks @rstims
android_channel_iddoes work when putting it in thenotificationpart of the payload. I wonder why iOS payload doesn't supportthread-id.
Can you help me with a payload
I am using below payload for customizing the sound
{"notification":{"title":"YOUR TITLE","body":"YOUR BODY" , "android_channel_id": "homeapp1"} }
hey @hiranya911 could you write a dummy payload to show how it should be structured?
I'm on [email protected] and I can successfully send push notifications to the device but I don't think the pushes are going to the channels i am specifying. I have 2 channels "miscellaneous" and "rn-push-notification-channel". The behavior on each is different. Yet when I specify the push to rn-push-notification-channel on my node server, it seems to always display the behavior in the miscellaneous channel. Any help here would be amazing..
const message = {
notification: pushTitleAndBody,
token: pushToken,
android: {
notification: {
title: "test",
body: 'hello world',
channel_id: "rn-push-notification-channel"
}
}
};
FirebaseAdmin.messaging().send(message)
.then((response) => {
console.log('Successfully sent message:', response);
res.sendStatus(200);
})
.catch((error) => {
console.log('Error sending message:', error);
res.sendStatus(500);
});
I've tried a dozen different ways including using android_channel_id and I get the same behavior each time.
It's channelId. See API docs: https://firebase.google.com/docs/reference/admin/node/admin.messaging.AndroidNotification.html#channelid
Or refer to the TypeScript typings shipped with the SDK.
@hiranya911 Yeah I should have added I tried channelId. Idk what the heck im doing wrong here. Ive tried about every combination possible after reading the docs and SO. Based on the code above can you think of anything else I might be doing wrong?
@hiranya911 Nevermind....my channel id display name and reference were slightly different and I forgot that. It works now. Thanks for responding to me!
the correct payload for someone need it:
"message": {
"token": "{{deviceToken}}",
"notification": {
"body": "This is an FCM notification message hello 23",
"title": "FCM Message",
"image": "image url"
},
"android": {
"notification": {
"channel_id": "channel_id_1"
}
},
"data": {
"key1": "42",
"key2": "sent by 21"
}
}
Most helpful comment
So what is the official way now to go about sending messages via node admin SDK now then?
We need to target API Level 26 and from what I understand, for notifications to be displayed, they need a set channel. Does anyone here have this working? How do I set the channel? Do I need to pin to an older version of the SDK that still allowed arbitrary keys (as suggested here)? Or what's the best way to make this work for now?