Adonis Firebase Notification Channel
Firebase Notification Channel for adonis-notifications.
Installation
- Add package:
$ npm i adonis-fcm-notification-channel --save
or
$ yarn add adonis-fcm-notification-channel
- Register providers inside the your
start/app.js
file.
const providers = ... 'adonis-fcm-notification-channel/providers/FcmNotificationChannelProvider' ...
- Add configuration to
config/services.js
file.
...fcm: apiKey: <YOUR API KEY> // optional requestOptions: proxy: 'http://127.0.0.1:8888' timeout: 5000 ...
See node-gcm for more information.
Usage example
// app/Model/User.js'use strict' const Lucid = static { return '@provider:Morphable' '@provider:HasDatabaseNotifications' '@provider:Notifiable' } // array, promise or generator { return 'token1' 'token2' ... } moduleexports = User
// app/Notifications/FcmNotification.js'use strict' const FcmMessage = { return 'fcm' } { // from object const message = collapse_key: 'demo' priority: 'high' content_available: true delay_while_idle: true time_to_live: 3 restricted_package_name: 'somePackageName' dry_run: true data: key1: 'message1' key2: 'message2' notification: title: 'Hello, World' icon: 'ic_launcher' body: 'This is a notification that will be displayed if your app is in the background.' sound: 'test_sound' badge: 'test_badge' tag: 'test_tag' color: 'test_color' click_action: 'test_click_action' body_loc_key: 'test_body_loc_key' body_loc_args: '["body0","body1"]' title_loc_key: 'test_title_loc_key' title_loc_args: '["title0","title1"]' // using fluent api message // using setters messagecollapseKey = 'demo' messagepriority = 'high' messagecontentAvailable = true messagedelayWhileIdle = true messagetimeToLive = 3 messagerestrictedPackageName = 'somePackageName' messagedryRun = true messagedata = key1: 'message1' key2: 'message2' messagetitle = 'Hello, World' messageicon = 'ic_launcher' messagebody = 'This is a notification that will be displayed if your app is in the background.' messagesound = 'test_sound' messagebadge = 'test_badge' messagetag = 'test_tag' messagecolor = 'test_color' messageclickAction = 'test_click_action' messagebodyLocKey = 'test_body_loc_key' messagebodyLocArgs = 'body0' 'body1' messagetitleLocKey = 'test_title_loc_key' messagetitleLocArgs = 'title0' 'title1' // you can set up configuration for current notification // using configure method message // or setters message messageapiKey = '<YOUR API KEY>' messagerequestOptions = proxy: 'http://127.0.0.1:8888' timeout: 5000 return message } moduleexports = MyNotification
or
// app/Notifications/FcmNotification.js'use strict' { return 'fcm' } { return collapse_key: 'demo' priority: 'high' content_available: true delay_while_idle: true time_to_live: 3 restricted_package_name: 'somePackageName' dry_run: true data: key1: 'message1' key2: 'message2' notification: title: 'Hello, World' icon: 'ic_launcher' body: 'This is a notification that will be displayed if your app is in the background.' sound: 'test_sound' badge: 'test_badge' tag: 'test_tag' color: 'test_color' click_action: 'test_click_action' body_loc_key: 'test_body_loc_key' body_loc_args: '["body0","body1"]' title_loc_key: 'test_title_loc_key' title_loc_args: '["title0","title1"]' } moduleexports = MyNotification
Credits
Support
Having trouble? Open an issue!
License
The MIT License (MIT). Please see License File for more information.