FCM.js
1.08 KB
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
// const fcm = require('firebase-admin');
const axios = require('axios');
// exports.initializeFCM = () => {
// fcm.initializeApp({
// credential: fcm.credential.applicationDefault(),
// });
// };
exports.sendPushMessage = async ({ deviceToken, title, body }) => {
// const notifyMessage = {
// notification : {
// title,
// body,
// },
// token : deviceToken,
// };
// fcm.messaging().send(notifyMessage).then(res => {
// console.log(res);
// }).catch(e => {
// console.log(e);
// });
const message = {
to : deviceToken,
notification : {
title,
body,
priority : 'high',
},
data : null,
}
const url = 'https://fcm.googleapis.com/fcm/send';
const result = await axios.post(url, message, {
headers : {
'Content-Type' : 'application/json',
// eslint-disable-next-line no-undef
'Authorization' : `key=${process.env.FCM_KEY}`,
},
});
console.log(result.data);
};