This only supports messages for Android devices. While FCM can handle sending messages to APNs and MPS, the code here assumes it is used for sending messages to Android clients only. Messages for iOS and web will be handled separately.
Messages are collapsed by message type. This means that while the target Android device is offline when multiple CheckEchoV1 message are sent to this device, only one of these same messages reaches the device. We currently support only one type, CheckEchoV1. FCM supports up to four collapse keys. So, we could add a few more in the future.
If the incoming message includes a property of dryRun
with the value true
then the message does not actually arrive on the target device. This feature is for testing this service.
To generate a private key file for your service account:
- In the Firebase console, open Settings > Service Accounts.
- Click Generate New Private Key, then confirm by clicking Generate Key.
- Securely store the JSON file containing the key.
- Set an environment variable to point to the absolute path of the file, like this:
export GOOGLE_APPLICATION_CREDENTIALS="/Users/XYZ/my-service-account-file.json"
- Build and start the service. Run:
npm run build && npm start
See https://firebase.google.com/docs/admin/setup#initialize-sdk.
- You start with our simple test Android app in Android Studio.
- Get the
google-services.json
file: Instructions. - Compile the app and run it on a real device or emulator. After subscribing, note the instance ID token. You can get that from logcat (hint: search for
Token
) or copy and paste it from the app UI.
See also: FCM docs to Set up a Firebase Cloud Messaging client app on Android.
- Open the Swagger UI, under
POST /v1/message/fcm
press the 'Try it out' button. - Paste the device token from the Android client setup to the JSON request body (replace the string REPLACE_ME with the actual device token you copied from the Android client).
- Press the 'Execute' button.