• Product

  • Solutions

  • Developers

  • Docs

  • Pricing

  • Cloud

Search icon
Strapi plugin logo for FCM

FCM

Send notifications to users or topics using Google's Firebase Cloud Messaging service.

Strapi v4 - FCM plugin

Send FCM notifications from Strapi.

NPM Version Monthly download on NPM codecov.io


Installation

From NPM:

npm install strapi-plugin-fcm

From YARN:

yarn add strapi-plugin-fcm

From Git:

  1. Clone the plugin into your Strapi project
cd /<path-to-your-strapi-project>/src

# create plugins folder if not exists
# mkdir plugins

# go to plugins folder
cd plugins

# clone the plugin code into a folder and skip the prefix
git clone https://github.com/itisnajim/strapi-plugin-fcm.git strapi-plugin-fcm
# install dependencies
cd strapi-plugin-fcm && yarn install # or npm install
  1. Enable the plugin in <root>/config/plugins.js .
1
2
3
4
5
6
7
8
module.exports = {
  // ...
  'strapi-plugin-fcm': {
    enabled: true,
    resolve: './src/plugins/strapi-plugin-fcm' // path to plugin folder
  },
  // ...
}
  1. Build the plugin
# back to project root and build the plugin
yarn build # or npm run build
# start
yarn develop # or npm run develop

Configuration

  • In the Firebase console, open Settings > Service Accounts.
  • Click Generate New Private Key, then confirm by clicking Generate Key.
  • Past the content of your downloaded service account json file into FCM Plugin Configuration > serviceAccount. (like in the picture below, then you may need to restart the server)

    Configuration
  • In the same interface 'FCM Plugin Configuration', optionally you can provide where the devices tokens are stored, in the picture example above, I store them in User -> deviceToken (strapi generate the users database table with the name up_users).

  • Optionally you can provide all the topics you have, in the 'FCM Topic' collection type (via the dashboard or via the api - Post requests).

    Topics

Usage

Via the dashboard

  • Enter the notification content.
  • Select targets to send to.
  • Click send!
    Admin Fcm
    Admin Fcm

Another way via the dashboard.

  • you can create a new entry in the 'FCM Notification' collection type and click publish to send to the FCM.

Via the api

  • First you have to enable and give routes permissions to a specific role or roles.
    Permissions
  • Then via an Http Client (axios, ajax, postman, curl or whatever) send a post request with the body data:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
    "data": {
        "title": "OKey",
        "body": "Test body",
        "image": "",
        "payload": "",
        "targetType": "topics",
        //or "targetType": "tokens",
        "target": "client_android",
        //or multiple topics "target": "client_android,client_ios",
        //or "target": "eyJhbGciOiJFUzI1...",
        //publishedAt: null //<<- uncomment this if you want to just add an entry as a draft to 'FCM Notification' collection without publishing and sending FCM.
    }
}
  • You can send an array too:
1
2
3
{
    "data": [{...entry1}, {...entry2}, {...entry3}, ...]
}

Trick

If you have saved the entries in the FCM Notification collection as drafts, you can scheduled them to be sent to FCM at a later time.


References

Install now

npm install strapi-plugin-fcm

STATS

20 GitHub stars76 weekly downloads

Last updated

43 days ago

Strapi Version

4.0.0 and above

Author

github profile image for itisnajim
itisnajim

Useful links

Create your own plugin

Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.