Docs Menu

Docs HomeAtlas App Services

Push Notifications [Deprecated]

On this page

  • Overview
  • Management Interface
  • Send a Push Notification
  • Set Up Clients to Receive Push Notifications
  • Rule Templates
  • Notifications Must Have a Specific Title
  • Notifications Must Be for a Specific Topic
  • Notifications Can Only Be Sent To a Limited Set of User IDs
  • Push Notification Rules
  • Notification Document Fields

Important

Third Party Services & Push Notifications Deprecation

Third party services and push notifications in App Services have been deprecated in favor of creating HTTP endpoints that use external dependencies in functions.

Webhooks have been renamed to HTTPS Endpoints with no change in behavior. You should migrate existing Webhooks.

Existing services will continue to work until November 1, 2024.

Because third party services and push notifications are now deprecated, they have been removed by default from the App Services UI. If you need to manage an existing third party service or push notification, you can add the configurations back to the UI by doing the following:

  • In the left navigation, under the Manage section, click App Settings.

  • Enable the toggle switch next to Temporarily Re-Enable 3rd Party Services, and then save your changes.

Atlas App Services supports integrating mobile (Android and iOS) apps with the Firebase Cloud Messaging (FCM) service to provide push notifications. You configure and send notification messages from within the App Services console, while clients register with Firebase Cloud Messaging (FCM) for messages sent to specific topics.

The Push Notifications screen in the App Services UI lets you write notification drafts, send notifications to users, and define notification rules.

There are four tabs in the Push Notifications screen:

Tab Name
Description
Draft

In the Draft tab, you can view a list of the draft messages. For the draft messages, you can:

  • Duplicate draft messages

  • Edit draft messages

  • Delete draft messages

Sent

The Sent tab shows the messages that App Services has already sent to registered clients. From here, you can view a list of the sent messages. For the sent messages, you can:

  • Resend sent messages.

  • Duplicate sent messages.

Config
In the Config tab, you provide the FCM credentials (Sender ID and Legacy API key).
Rules
You can optionally specify Push Notification Rules to restrict the types of push notifications that your application sends.

You can send new Push Notifications from the Push Notifications page. Click the Send New Notification button to open the Send New Notification dialog. In this dialog, you provide the notification message, label, and the relevant topic audience.

Sending a new Push Notification
click to enlarge
{
"%%args.notification.title": "Test Notification Please Ignore"
}
{
"%%args.to": "%%values.validTopics"
}
{
"%%true": {
"%function": {
"name": "allUserIdsAreValid",
"arguments": [
"%%args.userIds"
]
}
}
}

Note

This template calls an example function named allUserIdsAreValid that does the following:

  1. Accepts the list of User IDs provided in the userIds argument

  2. Queries MongoDB for a user document that matches the current user's id

  3. Compares the provided phone number to the number listed in the user document

  4. Returns the boolean result of the comparison

exports = function(toPhone) {
const mdb = context.services.get('mongodb-atlas');
const users = mdb.db('demo').collection('users');
const user = users.findOne({ _id: context.user.id });
return user.phoneNumber === toPhone;
}

To specify rules for Push Notifications, click on the Rules tab on the Push Notifications page.

Note

Unlike other services in App Services, rules for push notifications are optional. By default, all push notifications are allowed. However, once you specify a rule, the restrictions imposed by that rule will take effect.

The Push Notifications rules permit the following arguments. You can access them with the "%%args" expansion:

Field
Type
Description
userIds
Array of strings.
The user ids of the message recipients.
to
String
The recipient of the message. The value can be a device's registration token, a device group's notification key, or a single topic (prefixed with /topics/).
registrationTokens
Array of strings.
The list of registration tokens for the devices receiving the multicast message.
priority
string
The priority of the notification. Value is either "high" or "normal". Corresponds to the priority option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
collapseKey
string
The collapse key associated with collapsible messages. Corresponds to the collapse_key option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
contentAvailable
boolean
A flag that determines whether to awake idle client apps upon receipt of the message. Corresponds to the content_available option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
mutableContent
boolean
A flag that determines whether the notification content can be modified before being displayed to the user. Corresponds to the mutable_content option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
timeToLive
int

Maximum time (in milliseconds) to retain the message if the device is offline. Valid value range from 0 to 2419200.

Corresponds to the time_to_live option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.

data
JSON document
Payload for data message. data document consists of custom key-value pairs. Corresponds to the data option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
notification
JSON document
Payload for notification. notification document consists of predefined fields. Corresponds to the notification option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.

The following table lists the fields of the notification document that is available as a permitted field for Push Notifications rules. To access one of these fields in a rule, use "%%args.notification.<field>".

Field
Type
Description
title
string
The title of the notification. Corresponds to the title option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
body
string
The body of the notification. Corresponds to the body option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
sound
string
The sound to play upon receipt of the notification. Corresponds to the sound option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
clickAction
string
The action to take when a user click on the notification. Corresponds to the click_action option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
bodyLocKey
string
The key for localization of the body string. Corresponds to the body_loc_key option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
bodyLocArgs
string
The string values to replace format specifiers for localization in the body string. Corresponds to the body_loc_args option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
titleLocKey
string
The key for localization of the title string. Corresponds to the title_loc_key option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
titleLocArgs
string
The string values to replace format specifiers for localization in the title string. Corresponds to the title_loc_args option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
icon
string
For Android only. The notification icon. Corresponds to the icon option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
color
string
For Android only. Indicates the icon color in #rrggbb format. Corresponds to the color option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
tag
string
For Android only. If specified, each notification does not result in a new entry but replaces an existing entry with the specified tag. If unset, each notificaiton results in a new entry. Corresponds to the tag option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
badge
string
For iOS only. The badge on the gclient app home icon. Corresponds to the badge option for HTTP JSON messages via FCM. See the FCM HTTP protocol reference.
←  Partition-Based SyncThird-Party Services [Deprecated] →