Comparing version 1.5.0 to 1.6.0
23
app.js
const unirest = require('unirest'); | ||
const GOOGLE_FCM_ENDPOINT = 'https://fcm.googleapis.com/fcm/send'; | ||
const GOOGLE_FCM_SUBSCRIBE_ENDPOINT = 'https://iid.googleapis.com/iid/v1/'; | ||
@@ -31,2 +32,21 @@ class Fcmlly { | ||
async _subscribe(token,topic) { | ||
return new Promise((resolve,reject)=>{ | ||
if(!this.APIKey) | ||
throw Error('You must provide the APIKEY for your firebase applications.'); | ||
else if(typeof this.APIKey != 'string') | ||
throw Error('Your API key is incorrect'); | ||
unirest | ||
.get(GOOGLE_FCM_SUBSCRIBE_ENDPOINT + token + "/rel/topics/" + topic) | ||
.headers({'Authorization': `key=${ this.APIKey }`}) | ||
.then((response) => { | ||
resolve(response.raw_body); | ||
}) | ||
.catch((error) => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
async pushToUser(id,title,body,data=null,click_action=null) { | ||
@@ -58,2 +78,5 @@ const req = { notification: { | ||
async subscribeToTopic(token, topic) { | ||
return await this._subscribe(token,topic); | ||
} | ||
// async pushToUsers(ids,title,body,data=null,click_action=null) { | ||
@@ -60,0 +83,0 @@ // const req = { notification: { |
{ | ||
"name": "fcmlly", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "An integration for Google FCM and Node.js", | ||
@@ -5,0 +5,0 @@ "main": "app.js", |
@@ -52,4 +52,5 @@ Fcmlly - Integrate with Google cloud messaging easily | ||
* Subscribe a user to a topic | ||
```.subscribeToTopic('user FCM token', 'topic name') ``` | ||
     |
5256
79
55