-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
executable file
·51 lines (40 loc) · 1.45 KB
/
example.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
45
46
47
48
49
50
51
var pushpad = require('./index');
// process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
var AUTH_TOKEN = '5374d7dfeffa2eb49965624ba7596a09';
var PROJECT_ID = 123;
var user1 = 'user1';
var user2 = 'user2';
var user3 = 'user3';
var users = [user1, user2, user3];
var tags = ['segment1', 'segment2'];
var project = new pushpad.Pushpad({
authToken: AUTH_TOKEN,
projectId: PROJECT_ID
});
console.log('HMAC signature for the uid: %s is: %s', user1, project.signatureFor(user1));
var notification = new pushpad.Notification({
project: project,
body: 'Hello world!',
title: 'Website Name',
targetUrl: 'https://example.com'
});
notification.deliverTo(user1, function (err, result) {
console.log('Send notification to user:', user1);
console.log(err || result);
});
notification.deliverTo(users, function (err, result) {
console.log('Send notification to users:', users);
console.log(err || result);
});
notification.broadcast(function (err, result) {
console.log('Send broadcast notification');
console.log(err || result);
});
notification.deliverTo(users, { tags: tags }, function (err, result) {
console.log('Send notification to users:', users, 'if they have at least one of the following tags:', tags);
console.log(err || result);
});
notification.broadcast({ tags: tags }, function (err, result) {
console.log('Send broadcast notification to segments:', tags);
console.log(err || result);
});