Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Step 16.8: Create server side fcm service
  • Loading branch information
darkbasic committed Oct 16, 2017
1 parent 17e7fa8 commit e4b66ad
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 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();

0 comments on commit e4b66ad

Please sign in to comment.