-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapn.js
47 lines (42 loc) · 1.24 KB
/
apn.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
const apn = require('apn');
require('dotenv').config();
const logger = require('./logger');
// send push notification to iOS devices using APNs
exports.sendNotification = (
deviceToken, apnPayload,
) => {
const {
callId, messageText, localNumber, remoteNumber, roomId, roomToken,
} = apnPayload;
const options = {
cert: process.env.APNS_CERT_PATH,
key: process.env.APNS_KEY_PATH,
};
const apnProvider = new apn.Provider(options);
const note = new apn.Notification();
note.expiry = Math.floor(Date.now() / 1000) + 60; // Expires 1 minute from now.
note.badge = 3;
note.sound = 'ping.aiff';
note.alert = '\uD83D\uDCE7 \u2709 You have a new message';
// define your own payload
const payload = {
UUID: callId,
message: messageText,
localPhoneNumber: remoteNumber,
remotePhoneNumber: localNumber,
roomId,
roomToken,
};
note.payload = payload;
note.topic = process.env.APNS_VOICE_PUSH;
note.priority = 10;
note.pushType = 'alert';
apnProvider.send(note, deviceToken).then((err, result) => {
if (err) {
logger.info('Error sending message:');
logger.info(JSON.stringify(err));
}
logger.info('Successfully sent message:');
logger.info(JSON.stringify(result));
});
};