-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfirebase.ts
58 lines (53 loc) · 1.02 KB
/
firebase.ts
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
var admin;
var serviceAccount;
try {
admin = require("firebase-admin");
serviceAccount = require('/app/keys/ediplomas-wallet-firebase-adminsdk-1f8cq-d1fd260d2e.json');
// const certPath = admin.credential.cert(serviceAccount);
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
projectId: "ediplomas-wallet"
});
}
catch(e) {
console.log(e)
console.error("Error: Notification capability is not enabled")
}
const sendPushNotification = async (fcm_token, title, body) => {
try {
let message = {
notification: {
title,
body,
},
data: {
},
apns: {
payload: {
aps: {
sound: 'default',
},
},
},
android: {
notification: {
sound: 'default',
},
},
token: fcm_token,
};
admin.messaging().send(message)
.then((response) => {
console.log(response + ' messages were sent successfully');
})
.catch(err => {
console.log("failed to send firebase message")
});
}
catch(err) {
throw err;
}
}
export {
sendPushNotification
}