Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not clear how to set channel for messaging #168

Closed
esprehn opened this issue Dec 21, 2017 · 8 comments
Closed

Not clear how to set channel for messaging #168

esprehn opened this issue Dec 21, 2017 · 8 comments

Comments

@esprehn
Copy link

esprehn commented Dec 21, 2017

There's value mentions of android_channel_id in some stackoverflow posts, but nothing in the docs or in this repo. How do you set the channel? The console has a field for it even though the API makes no mention of it.

@google-oss-bot
Copy link

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

@google-oss-bot
Copy link

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@hiranya911
Copy link
Contributor

NotificationMessagePayload type is defined as follows:

type NotificationMessagePayload = {
    tag?: string;
    body?: string;
    icon?: string;
    badge?: string;
    color?: string;
    sound?: string;
    title?: string;
    bodyLocKey?: string;
    bodyLocArgs?: string;
    clickAction?: string;
    titleLocKey?: string;
    titleLocArgs?: string;
    [key: string]: string | undefined;
  };

Since it allows arbitrary keys, I would expect that if you just add android_channel_id under notification, it will just work.

@esprehn
Copy link
Author

esprehn commented Dec 22, 2017

Can something be added to the docs? It's strange the web console has a field for this and nothing is mentioned in the docs for how to do it programmatically.

@mdgagne
Copy link

mdgagne commented Apr 19, 2018

@hiranya911 this package no longer allows arbitrary keys in the notification object, how should the android notification channel be set when sending messages?

@hiranya911
Copy link
Contributor

You can still use the legacy APIs for this. The new REST API doesn't support it as far as I can tell: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#AndroidConfig

SDK's admin.messaging.send() API cannot support it until it's exposed in the REST interface.

@Stefan300381
Copy link

Stefan300381 commented Jun 9, 2020

hey guys, bringing this old thread back to life. it took me a few days to find out how to use firebase admin sdk with node.js and assign a channel ID to a notification. thanks for the post above I just added "android_channel_id" to my notification payload object, see below.

It works, but is it the correct way?

//prepare firebase cloud messaging push notification
var notification_message =  {                                                                                                                    
  notification: {
     title: "mytopic",
     body: "mybody",
     android_channel_id: "mychannelid"
  }
};

followed by something like:
fb_admin.messaging().sendToDevice(tokenarray, notification_message, options)

@hiranya911
Copy link
Contributor

That looks correct for the legacy API.

Channel ID is also supported by the new (v1) API now: https://firebase.google.com/docs/reference/admin/node/admin.messaging.AndroidNotification#optional-channelid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants