-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-test-notification.js
63 lines (52 loc) · 1.49 KB
/
send-test-notification.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
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Sending plain data notifications via twilio
*/
const config = require('./config');
const accountSid = config.ACCOUNT_SID;
const authToken = config.AUTH_TOKEN;
const serviceId = config.SERVICE_ID;
const userIdentity = 'user-1';
const fcmAddress = config.FCM_ADDRESS;
const client = require('twilio')(accountSid, authToken);
// bind user (only the 1st time)
/*
try {
client.notify.services(serviceId)
.bindings
.create({
identity: userIdentity,
bindingType: 'fcm',
address: fcmAddress
})
.then(binding => console.log(binding.sid));
} catch(err) {
console.log("twilio binding error");
console.log(err);
}
*/
// send push notification
const dataCommon = {
title: 'my remote title',
message: 'my remote message'
};
const dataEvent = {
title: 'event title',
message: 'event message',
media: 'http://red-msk.ru/wp-content/uploads/2019/02/canva-photo-editor-22.png'
};
const dataEventWithUrl = {
title: 'event title',
message: 'event message',
media: 'http://red-msk.ru/wp-content/uploads/2019/02/canva-photo-editor-22.png',
url: 'https://google.com'
};
try {
client.notify.services(serviceId)
.notifications
.create({data: dataCommon, identity: userIdentity})
.then(notification => console.log(notification.sid));
} catch(err) {
console.log("error on sending notification");
console.log(err);
}
console.log("finished");