node-fcm-hero
FCM interface with super powers. Send push notifications to android/ios in a simple way
Installation
How it works
To use this lib, you have to import:
const fcm = ;const firebase = ;const push = ;
The config file must have this format:
The cert param has to be the path to yor firebase json file.
If you already have an initializated instance of firebase-admin module, you can pass directly the messaging function to initialize the node-fcm-hero. Ie:
const fcm = ;const firebase = ;const push = ;
Send notification
To send a push notification you will need to call the send method. Ie:
const event = token : '' type : '' payload : '' pushType: ''push ;
Push notification type
You can set the pushType attribute of the event to define the kind of template to send. This pushType must be a string with the name of one of the custom templates you initialize to the project.
If you do not set any template or it didn't find in the type in the templates folder, the notification will fail.
You can make this work like an event Redux flow, passing the type and defining a template file per event you want to push.
If the event type don't macht with any template, the node-fcm-hero will return a unsuccess json object:
Custom templates
You can override the default types and templates for your own, setting in the firebase config object a templatesPath field with the string to the path.
You can find examples of the templates format under the folder 'exampleTemplates'.
Event listeners
node-fcm-hero has a default events pre configured to help you to subscribe to listeners depending of this default events.
This is the list of the default events:
push.events :
.UNINSTALLED
.RENEW_CREDENTIALS
.FIREBASE_ERROR
.ERROR
.SUCCESS
To subscribe and catch some of this events, you need to add a callback funtion asociated to the event:
push;push;push;
UNINSTALLED event
Will return every single token marked as app uninstalled after the called send function.
Error handling
If any error happends, the node-fcm-hero will return a json object with the success field equal to 0. Also, it will notify to the on error listeners.
Test
To make the integration test work, you need to provide your own instance of firebase admin messaging or set your configuration file with the route to your firebase-adminsdk.json. Also you need to you provide at least one working firebase token and one uninstalled to cover all the best scenarios. After that, delete the .skip of the nodeFcmHero.e2e.test.js
Sorry for this, but i don't want to see how my phone 💥💥💥
Powered by:
Lingbe App