Closed sattha closed 9 years ago
Hi! This is actually a question I have received before, and I think we should update the README to fit the truth. I will leave this issue open until this happens.
There is a simple way to do what you want. Simply pass the topic instead of the registration ids:
sender.send(message, "/some/topic", callback);
This puts "/some/topic"
in the to
field of the message JSON.
@hypesystem:
I can't get your example to work with send()
. It seems to come from this line: https://github.com/ToothlessGear/node-gcm/blob/master/lib/sender.js#L124.
sendNoRetry()
worked fine.
To the people who would try to copy-paste the example like me: don't use '/some/topic'
, topic names have to start with /topics/
!
Ah! You are correct! It only works with sendNoRetry
at the moment.
Another reason for leaving this issue open:
@bastienleonard I would love a PR if you have the time :)
@hypesystem I'll try to do that after work!
Just had a thought: changing the interface would be a breaking change, and we are not quite ready to release anything called "1.0" yet.
I would prefer if you, in the PR, could make a new method on the Sender
called sendTo
(or similar) which works with topics/notification keys (things that go in the to
field) :)
Right, not converting to an array would break compatibility for some users.
How do you feel about send()
accepting an explicit object, e.g. { "topic": "/topics/global" }
?
Topics and registration IDs being passed in the same JSON key to GCM seems like an implementation detail that shouldn't necessarily be present in the Node API.
I like that solution for not breaking compatibility :) go ahead!
I get a 400
whenever I try to use the topic
section. Or, must I pass ids when sending a push to the /topics
which I don't think so. Since I get a 400
and that according to https://developers.google.com/cloud-messaging/http-server-ref#table1 means the data is not well structured and this is my data being sent too
var message = new gcm.Message({delayWhileIdle: true, priority: 'high', notification:{title:'Request', icon: 'ic_launcher', body: successData[0].Status}});
sendGlobalPush: function(message){ sender.sendNoRetry(message, {topic: '/topics/global'}, function(err, result){ if (err) { console.log(err); } else { console.log(result); } });
Any help. Thanks @hypesystem @bastienleonard
The topic support is not yet released, but will be in node-gcm v.0.12
Ahn, but it's in the README file
// Send to a topic, with no retry this time sender.sendNoRetry(message, { topic: '/topics/global' }, function (err, result) { if(err) console.error(err); else console.log(result); });
The README file is in sync with the master branch. Please refer to the README on npmjs.org for the most recent released one.
This has now been released in 0.12.0
because registerIDs is required and cannot empty or null