Easy interface for Google's Cloud Messaging service (now Firebase Cloud Messaging)
eladnava on master
#360: Improve code sample for u… (compare)
ToothlessGear on snyk-upgrade-0ad01475386a1990f816e6b025fab448
fix: upgrade debug from 3.1.0 t… (compare)
ToothlessGear on snyk-upgrade-0ad01475386a1990f816e6b025fab448
eladnava on master
Fix #358: rectify coding mistak… (compare)
new gcm.Sender(’SERVER_KEY’);
Hello, i try this, i found error401. var gcm = require('node-gcm');
var apiKey = "AIzaSyDxxs9S8uvjiQJcvml09narkc_dIpAY1gs";
var deviceID = "ftUAFGfn8xg:APA91bGun-NEejGn30reWXK5wyidMK094AP02a3ACFcGotBiM3eeDEhSTZKI-6vs63bGKfJ4ffcBD9ZEVc2L6X1fT0jtf7YtwJtRBqO_WMByFKoASaRRYFHQyVCUmvc3nmBmx";
var service = new gcm.Sender(apiKey);
var message = new gcm.Message();
message.addData('title', 'Hello, World');
message.addData('body', 'This is a notification that will be displayed ASAP.');
service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
if(err) console.error(err);
else console.log(response);
});
Hi, I'm new to FCM and node-gcm and try to get it run. With the Example-application I get a success-response but the notification doesn't appear on my test device?
var gcm = require('node-gcm');
// Set up the sender with your GCM/FCM API key (declare this once for multiple messages)
var sender = new gcm.Sender('AAAAhziPlIg**');
// Prepare a message to be sent
var message = new gcm.Message({
data: { key1: 'nodetest' }
});
// Specify which registration IDs to deliver the message to
var regTokens = ['eFtDerXHzCE:APA91bGEnICDH6B**'];
// Actually send the message
sender.send(message, { registrationTokens: regTokens }, function (err, response) {
if (err) console.error(err);
else console.log(response);
});
When I try it via FCM Webinterface it works fine.
try sending this message instead:
const notification = new gcm.Message({
priority: 'high',
contentAvailable: true,
delayWhileIdle: false,
timeToLive: 3,
restrictedPackageName: 'your app id here ex: com.xxx.xxxxxx',
dryRun: false,
notification: {
title: 'liveScores',
icon: 'ic_launcher',
sound: 'default',
body: 'your notificaiton message here'
}
});
Hi all!
Today, a lot of (all?) Android devs got an email saying that by April 11, 2019 we must migrate from using the old GCM infrastructure to the new Firebase Cloud Messaging. I just wanted to let you all know that node-gcm already uses FCM and has since version 0.14.1 :-) Feel free to ask more questions here: ToothlessGear/node-gcm#317
Best,
Niels
util.promisify
is one way of doing this: https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original
let sendPromise = new Promise((resolve, reject) => sender.send(message, { registrationTokens: regTokens }, (error, response) => {
if(error) {
reject(error);
}
else {
resolve(response);
}
});
await sendPromise
.
The first step would be figuring out which methods we need to provide promisified versions of. I am thinking that an easy interface to expose would be something like sender.promise.send
, which would be the promisified version of sender.send
?
To do this, you would have to create a promise
object on Sender
's prototype in here: https://github.com/ToothlessGear/node-gcm/blob/master/lib/sender.js and then make sure that promise
has a function send
which returns a promise.
Does that approach sound reasonable to you? If so, I'd love to see your code for doing this. You can make an early PR and we can discuss it further there :-)