diff --git a/api/server/services/fcm.ts b/api/server/services/fcm.ts new file mode 100644 index 000000000..ea4a555b9 --- /dev/null +++ b/api/server/services/fcm.ts @@ -0,0 +1,30 @@ +import fetch from 'node-fetch'; + +export interface FcmNotification { + title: string; + text: string; +} + +export class FcmService { + private key: string = Meteor.settings.private.fcm.key; + + sendNotification(notification: FcmNotification, destination: string) { + const body = { + notification: notification, + to: destination + }; + + const options = { + method: 'POST', + body: JSON.stringify(body), + headers: { + "Content-Type": "application/json", + Authorization: `key=${this.key}` + }, + }; + + return fetch("https://fcm.googleapis.com/fcm/send", options); + } +} + +export const fcmService = new FcmService();