ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 208 forks source link

Unable to send notification on multiple topics (more than 5) #326

Closed djvickx closed 5 years ago

djvickx commented 5 years ago

Hello, I am using firebase condition to send notification on multiple topics. It works like charm for upto 5 topics but I need to send on more than 5 topics. Please guide how I can do that. Following is the code:

condition = "'TopicA' in topics || 'TopicB' in topics || 'TopicC' in topics || 'TopicD' in topics || 'TopicE' in topics || 'TopicF' in topics || 'TopicG' in topics "
string serverKey = //SERVER_KEY

WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
tRequest.ContentType = "application/json";
var objNotification = new
{
condition = condition,
priority = "high",
data = //NOTIFICATION DATA
};
WebResponse tResponse = tRequest.GetResponse();
hypesystem commented 5 years ago

Great, thank you for moving this to a separate issue.

I can see here that you are not using our library for sending notifications via FCM in Node.js. In fact, I'm not quite sure which programming language you are using at all. It looks like C#?

The proper way of using more conditions, I think, would be splitting the topics, and sending multiple requests to FCM.

If you are not using our library, I'm afraid we can't help much, and StackOverflow or AskQuestions.Tech would be more appropriate channels to look for answers in.

djvickx commented 5 years ago

Thanks for the reply @hypesystem I am using Google Firebase APIs to send notifications. And yes its C#. I can't send multiple requests by splitting topics as it will result in duplicate notifications to users who have subscribed to all topics. Can u please guide if I use FCM in node.js then I can send notification to multiple topics without splitting the topics?

Thanks, Waqas

hypesystem commented 5 years ago

Ah! I see the issue... I'm not sure I have a good solution for this, I'm afraid 😦

eladnava commented 5 years ago

One option is to keep track of and ignore duplicate notifications received on the clientside by sending a unique identifier with each unique notification and logging it to prevent future notifications with the same ID from being handled.

This requires not to use the notification fields but to build the notification manually.

Please consult StackOverflow for further help.