Introduction
Channels
Templates
Contacts
Messages
API

firebase Firebase Cloud Messaging

Firebase Cloud Messaging (FCM) is the new version of Google Cloud Messaging (GCM). It allows mobile developers to grab iOS & Android device tokens and send push notifications using a single API.

Features

Firebase specific features
Cross-platform API Send iOS and Android messages using a single API.
100% free Send free and unlimited notifications across Android, and iOS.
Multicast Your contact will receive a copy of the message on all it's registered devices.

Connect Firebase

  1. Go to your Firebase "Project settings"
  2. Open the "Cloud Messaging" tab
  3. Grab your "Server key" and "Sender ID"

Sending messages with Firebase

With FCM your can send 2 types of messages: "display notifications" and "data payloads".

As soon as you provide a title, text, click action etc... the notification will be displayed on the phone. You can also provide a data payload with a displayed notification.

To only send a data payload, use the channelOptions property like this:


    {
      "messages": [{
        "notification": "push-data",
        "template": "data",
        "channel": "firebase-myproject",
        "channelOptions": {
          "data": {
            "my-key": "value"
          }
        },
        "contact": "123"
      }]
    }
    

Available settings

The Firebase settings are defined at the template level from the Notifuse interface when you create/update a template.

If you don't plan to customize some settings when you send a message (via API), you can skip the following table.

The settings you can overwrite when you send a message via API are marked in the Available in column.
Parameter Available in Description
fcmTokens
required array of FCM tokens
message The Firebase registration device tokens.
kind
required string
template The kind of message you want to send: display or data.
title
optional string
template Notification title. Only visible on Android and iOS wear devices. Templating markup allowed.
text
optional string
template Required for "display" notifications. Content of your message. Templating markup allowed.
textMacro
optional string
template Id of the page of macros used in the text content of your message.
testData
optional JSON object
template JSON object of fake data used to test your templates.
priority
optional string
template Your message priority normal or high. Default is normal. On iOS, these correspond to APNs priorities 5 and 10. A high priority will wake up a sleeping device.
sound
optional string
template Sound for "display" messages. Default is default. Sound files must reside in /res/raw/ for Android and in Library/Sounds or the main bundle for iOS.
timeToLive
optional integer
template Lifespan in seconds of the message if the device is offline. 4 weeks max/default.
collapseKey
optional string
template Identifies a group of messages that can be collapsed (at the FCM level) if the device is offline.
restrictedPackageName
optional string
template This parameter specifies the package name of the application where the registration tokens must match in order to receive the message.
clickAction
optional string
template Indicates the action associated with a user click on the notification. Corresponds to category in the APNs payload, and launches an activity with a matching intent filter in Android.
contentAvailable
optional boolean
template On iOS, use this field to represent content-available in the APNs payload. When a notification or message is sent and this is set to true, an inactive client app is awoken. On Android, data messages wake the app by default.
badge
optional integer
template, message iOS only. Indicates the badge on the client app home icon.
icon
optional string
template Android only. Indicates notification icon. Sets value to myicon for drawable resource myicon.
tag
optional string
template Android only. Indicates whether each notification results in a new entry in the notification drawer on Android.
If not set, each request creates a new notification.
If set, and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.
color
optional string
template Android only. Indicates color of the icon, expressed in #rrggbb format
data
optional JSON object
message Attach a JSON payload to your notification. Mostly used for "data" messages.

On iOS, if the message is sent via APNS, it represents the custom data fields. If it is sent via FCM connection server, it would be represented as key value dictionary in AppDelegate application:didReceiveRemoteNotification:.

On Android, this would result in an intent extra named score with the string value 3x1.

The key should not be a reserved word ("from" or any word starting with "google" or "gcm"). Do not use any of the words defined in this table (such as collapse_key).

Values in string types are recommended. You have to convert values in objects or other non-string data types (e.g., integers or booleans) to string.
dryRun
optional boolean
message Default is false. When set to true, allows developers to test a request without actually sending a message.

Next: How to use the templates ยป