Push notifications

Push notifications notify user devices whether or not an application is open and running. They deliver information, such as app updates, social media alerts, or promotional offers, directly to the user’s screen. Ably sends push notifications to devices using Google’s Firebase Cloud Messaging service (FCM) and Apple’s Push Notification Service (APNs). Push notifications don’t require a device to stay connected to Ably. Instead, a device’s operating system maintains its own battery-effficient transport to receive notifications.

You can publish push notifications to user devices directly or via channels.

Publishing directly sends push notifications to specific devices identified by unique identifiers, such as a deviceId or a clientId. This approach is akin to sending a personal message or alerts directly to an individual user’s device, bypassing the need for channel subscriptions. It excels in targeted and personalized communications, such as alerts specific to a user’s actions, account notifications, or customized updates.

Publishing via channels uses a Pub/Sub model. Messages are sent to channels to which multiple devices can subscribe. When a message is published to a channel, all devices subscribed to that channel receive the notification. This approach is particularly powerful for simultaneously publishing messages to multiple users.

Integrating push notifications into your application includes a few essential configuration steps.

The following diagram demonstrates the push notification process:

Push Notifications in Ably

Configuring push notifications sets your device’s FCM or APNs to operate with the Ably platform. This process includes inputting the necessary credentials into your Ably dashboard.

Activate devices for push notifications directly or via a server:

  • Activating directly enables the device to recieve push notifications. This process involves obtaining a unique identifier for the device, which serves as a push recipient. Direct activation is typically used when the application can directly handle device registration without intermediaries, providing a straightforward approach to activation.
  • Activating via server delegates the activation process to your server rather than handling it directly on the device. This approach is often preferred to minimize the capabilities assigned to an untrusted device, enhancing security and control. By managing device registrations server-side, you can also centralize activation logistics and handle sensitive operations away from the client.

Publish push notifications using Ably via channels or directly:

  • Publishing directly allows for the delivery of push notifications straight to individual devices. This process is beneficial for targeting specific devices with unique deviceIds, clientIds associated with one or more devices, or recipient details particular to the push notification service. Direct publishing is akin to sending a personal, targeted message to a user’s device.
  • Publishing via channels operates similarly to Ably’s Pub/Sub messaging model, broadcasting notifications to all channel subscribers. This process leverages Ably channels to distribute push notifications efficiently to all devices subscribed to those channels. It is ideal for scenarios where the same information, such as alerts or updates, needs to be sent to multiple users.

Subscribe

If you publish via channels, devices must subscribe to those channels to receive notifications. This process offers flexibility in managing and delivering notifications. Subscriptions can be made using the deviceId or clientId:

  • The deviceId process subscribes a device directly to a channel using its unique deviceId, assigned by Ably, for push notifications upon device activation. This process links the subscription to the device.
  • The clientId process subscribes all devices tied to a particular clientId to a channel in one action, for example the same user’s laptop and mobile phone. This approach is useful for subscribing multiple devices simultaneously.

Ably’s push admin API is a set of functionalities designed for backend servers to manage push notification tasks. It handles registering devices for push notifications, managing subscriptions to specific channels, and sending push notifications directly to devices or users identified by a client identifier. It can be used with both the realtime and REST interfaces of an Ably SDK.

Using the push Admin API requires explicit capabilities within a client’s credentials:

  • Access using the push-admin capabilities grants full API access, enabling the management of registrations and subscriptions for all devices.
  • Access using the push-subscribe capabilities designates a client as a push target device. It can only manage its own registration and subscriptions, not those of other devices.

Each push target device is associated with a unique deviceId and authentication credentials. Authentication can be achieved in two ways when using the push Admin API:

  • By utilizing an Ably token containing the device’s deviceId.
  • By employing a standard Ably key or Token, with a deviceIdentityToken, a credential generated during registration to assert the device’s identity, included in the request header.

The sevice credential management is handled by the Ably SDK, removing the need for the client application to manage device credentials unless accessing the push admin API directly via HTTP.

Push notification process