-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcm.js
executable file
·45 lines (35 loc) · 861 Bytes
/
gcm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env node
var program = require('commander');
program
.version('1.0.0')
.option('--id <id>', '')
.option('--key <key>', '')
.option('--token <token>', '')
.option('-m <msg>', '')
.option('--dryrun', 'Dryrun')
.parse(process.argv);
var gcmId = program.id;
var gcmKey = program.key;
var msg = program.msg;
var token = program.token;
if (!gcmId) {
console.error('missing gcmId');
}
if (!gcmKey) {
console.error('missing gcmKey');
process.exit();
}
if (!token) {
console.error('missing token');
process.exit();
}
console.log(gcmId);
console.log(gcmKey);
var gcm = require('node-gcm');
var sender = new gcm.Sender(gcmKey);
var message = new gcm.Message();
message.addNotification('title', msg);
sender.send(message, token, function (err, response) {
if (err) console.error(err);
else console.log(response);
});