-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend-firebase-message-https.js
More file actions
52 lines (49 loc) · 1.35 KB
/
Copy pathsend-firebase-message-https.js
File metadata and controls
52 lines (49 loc) · 1.35 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
45
46
47
48
49
50
51
52
async function generateAccessToken() {
return new Promise((resolve, reject) => {
const key = require("./File.json");
const jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
SCOPES,
null,
);
jwtClient.authorize((err, tokens) => {
if (err) {
reject(err);
return;
}
resolve(tokens.access_token);
});
});
}
generateAccessToken().then((token) => {
console.log("Generated Access Token:", token); // Log the token
const accessToken = token;
async function sendDirectMessage() {
const url = `${base}/v1/projects/your-project/messages:send`;
const payload = {
message: {
token: "fcm-token",
notification: {
title: "Hello World!",
body: "This is a test to see if notifications are working...",
image: null,
},
data: {
},
},
};
const response = await fetch(url, {
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
method: "POST",
body: JSON.stringify(payload),
});
const responseData = await response.json(); // Get the response data
console.log("Direct Message Response:", responseData); // Log the response data
}
sendDirectMessage();
}).catch(console.error);