-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapns.js
More file actions
30 lines (28 loc) · 851 Bytes
/
Copy pathapns.js
File metadata and controls
30 lines (28 loc) · 851 Bytes
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
/**
* Apple Push Notification Service
* Cert info from:
* https://github.com/Finb/bark-server/blob/master/deploy/AuthKey_LH4T9V5U4R_5U8LBRXG3A.p8
*/
const { ApnsClient, Notification } = require("apns2");
const apns = new ApnsClient({
keyId: "LH4T9V5U4R",
team: "5U8LBRXG3A",
defaultTopic: "me.fin.bark",
signingKey: `
-----BEGIN PRIVATE KEY-----
MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQg4vtC3g5L5HgKGJ2+
T1eA0tOivREvEAY2g+juRXJkYL2gCgYIKoZIzj0DAQehRANCAASmOs3JkSyoGEWZ
sUGxFs/4pw1rIlSV2IC19M8u3G5kq36upOwyFWj9Gi3Ejc9d3sC7+SHRqXrEAJow
8/7tRpV+
-----END PRIVATE KEY-----
`});
/**
* Push message to device
* @param {string} deviceToken
* @param {object} payload
* @returns
*/
apns.push = async function (deviceToken, payload) {
return await apns.send(new Notification(deviceToken, payload));
}
module.exports = apns;