Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create sendPushNotification method
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 5fb2293 commit af8da9a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions functions/gcloud.ts
Expand Up @@ -269,3 +269,32 @@ export async function queryLogs(user: number, context: RequestContext) {
).batch?.entityResults ?? []
);
}

export async function sendPushNotification(
env: Env,
title: string,
body: string,
token?: string,
) {
const message = JSON.stringify({
notification: {
body,
title,
},
token,
});

const notifResp = await fetch(
"https://fcm.googleapis.com/v1/projects/car-crushers-mobile/messages:send",
{
body: JSON.stringify({ message }),
headers: {
authorization: `Bearer ${await GetAccessToken(env)}`,
"content-type": "application/json",
},
method: "POST",
},
);

if (!notifResp.ok) throw new Error(await notifResp.json());
}

0 comments on commit af8da9a

Please sign in to comment.