Learn how to use the Firebase Cloud Messaging (FCM) provider to send push notifications using Novu
Firebase Cloud Messaging (opens in a new tab) is a free notification delivery service provided by Google Firebase.
To enable the FCM integration, you need to get your service account key from the Firebase Console (opens in a new tab).
Generating a Service Account Key JSON
To acquire the account key JSON file for your service account
- Select your project, and click the gear icon on the top of the sidebar.
- Head to project settings.
- Navigate to the service account tab.
- Click Generate New Private Key, then confirm by clicking Generate Key.
- Clicking Generate Key downloads the JSON file.
After that, paste the entire JSON file content in the Service Account field of the FCM provider in the integration store on Novu’s web dashboard.
Make sure your service account json content contains these fields
{
"type": "service_account",
"project_id": "PROJECT_ID",
"private_key_id": "PRIVATE_KEY_ID",
"private_key": "PRIVATE_KEY",
"client_email": "FIREBASE_ADMIN_SDK_EMAIL",
"client_id": "CLIENT_ID",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "CLIENT_X509_CERT_URL"
}
FCM Overrides
The overrides field supports apns, android, webpush and fcmOptions overrides
Setting Device Token
Before triggering the notification to a subscriber(user) with push as a step in the workflow, make sure you have added the subscriber’s device token as follows:
import {
Novu,
PushProviderIdEnum
} from '@novu/node';
const novu = new Novu("<NOVU_API_KEY>");
await novu.subscribers.setCredentials(
'subscriberId',
PushProviderIdEnum.FCM,
{deviceTokens: ['token1', 'token2']},
'fcm-MnGLxp8uy'
);
Checkout the API reference for more details.
FCM Cost
As per Firebase pricing (opens in a new tab), Cloud Messaging product is free of cost to use. If other Firebase products are used, the cost will be charged as per the product.