Azure / azure-notificationhubs-dotnet

.NET SDK for Azure Notification Hubs
MIT License
70 stars 123 forks source link

How to set channel for FCM notification #182

Closed Oleksandr-Ieremenko-Akvelon closed 3 years ago

Oleksandr-Ieremenko-Akvelon commented 3 years ago

Query/Question When I send messages from FCM or Azure Hub portal it sends it with fcm_fallback_notification_channel channelId in payload: {"channelId": "fcm_fallback_notification_channel", "color": null, "data": {"property1": "value1", "property2": "42"}, "finish": [Function finish], "foreground": true, "id": "-2071478046", "message": "This is a sample notification delivered by Azure Notification Hubs.", "priority": "high", "sound": null, "tag": null, "title": "Notification Hub Test Notification Secure Sub 4", "userInteraction": false, "visibility": "private"} what corresponds to default FCM channel created by FCM SDK. When I use Microsoft.Azure.NotificationHubs, Version=4.1.0.0 I don't see a way to set the channel manually or use default one. A message is going out without a channelId even if I add it to content private const string FcmSampleNotificationContent = "{\"channelId\": \"fcm_fallback_notification_channel\", \"data\":{\"message\":\"Notification Hub test notification from SDK sample 2\"}}"; and send via SendFcmNativeNotificationAsync(FcmSampleNotificationContent). As a result I get such messages on a device {"data": {"message": "Notification Hub test notification from SDK sample 2"}, "finish": [Function finish], "foreground": true, "id": "-1023128206", "userInteraction": false} but they are not pop up by Android OS. So question is: how can I set up a channelId for FCM notifications?

Why is this not a Bug or a feature Request? Because lack of knowledge on the lib I'm not sure the functionality doesn't exist.

Setup (please complete the following information if applicable):

Oleksandr-Ieremenko-Akvelon commented 3 years ago

I found an answer, in the samples message payload is outdated, correct one for FCM is: private const string FcmSampleNotificationContent = @"{ ""notification"": {""title"":""Notification Hub test notification from SDK sample"", ""body"":""Body of notification"" }}"; look into Firebase docs: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages This payload set default channel correctly.