From f93664389597cc5c4a1b15b2ef428641114c9b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Belli?= Date: Thu, 8 Jun 2017 23:30:29 +0200 Subject: [PATCH] Step 16.8: Create server side fcm service --- api/server/services/fcm.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 api/server/services/fcm.ts 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();