Overview

LAST EDIT Nov 06 2024

Stream Chat supports push notifications through Firebase Cloud Messaging, Apple Push Notification (APN), Huawei Push and Xiaomi Push.

Push notifications are only sent for new messages and not for other events. You can use Webhooks to send push notifications on other types of events.

Setting up Push

Copied!

Push is available to Stream Chat integrations running in a mobile environment.

Depending on which Stream Chat SDK you are using, the process for setting up push notifications will be slightly different. Follow the guide for your chosen SDK:

Push Delivery Rules

Copied!

Push message delivery behaves according to these rules:

  • Push notifications are sent only for new messages.
  • Only channel members receive push messages.
  • Members receive push notifications regardless of their online status.
  • Replies inside a thread are only sent to users that are part of that thread:
    • They posted at least one message
    • They were mentioned
  • Messages from muted users are not sent.
  • Messages are sent to all registered devices for a user (up to 25) .
  • Up to 100 members of a channel will receive push notifications for push v1.
  • Up to 1000 members of a channel will receive push notifications for push v2. This limit can be increased per app through customer support.
  • skip_push is marked as false, as described here.
  • push_notifications is enabled (default) on the channel type for message is sent.
Push notifications require membership. Watching a channel isn't enough.

Handling Push Notifications on the Foreground

Copied!

Both iOS and Android discard push notifications when your application is on the foreground.

You can configure this on your application and decide what to do when a push notification is received while the app is on the foreground.

Push Notification Payload

Copied!

Push notifications are delivered as data payloads that the SDK can use to convert into the same data types that are received when working with the APIs.

When a message received by the Chat API, according to the delivery rules, it kicks a job that sends a regular data message (as below) to configured push providers on your app. According to the battery and the online status of the device, push providers deliver this payload to the actual devices. When a device receives the payload, it's passed to the SDK which connects to Chat API to receive regular message and channel records and unmarshals them into in-memory objects and gives control to you by passing these objects. At this point, your application can use these objects to generate any push notification to be shown to the user.

This is the main payload which will be sent to each configured provider:

On both Android and iOS the SDK will convert the payload in channel and message types and allow you to customize the notification message.

You can find more details, examples and guides on specific use-cases on the specific SDK docs.

Make sure to read the "Push Templates" page if your application was created before January 18, 2022 or was not upgraded to push v2.
Version 1 (legacy) of push notifications won't be removed but there won't be any new features. That's why new applications are highly recommended to use version 2 from the beginning to leverage upcoming new features.

Push Notification Configuration

Copied!

Firebase

Copied!
  • v2: Requires a service worker account from your FCM project.

Firebase console → project settings (top left)  → service accounts (4th sub header) → generate a new private key

Export your key and upload in the firebase credentials field in dashboard. A sample content:

  • v1: Requires a server key

Firebase console → project settings (top left)  → cloud messaging (2th sub header) → add server key

It will generate a long key and save in the firebase server key field in dashboard. A sample key:

AAAAktWCgMU:APA91bGIcyTcdvT0DQqDIfdFPyc5Bk8hH-z5EfFcWI7WFiXOFDKhcspm-Uy_znvEvXfaOOZrFMIP1XAK8drZr7vM70UihXtyz7ZsL3KiSkgkrXk7BJgZZ_VybPLc6ug9baXIAw1zz2nk

For other providers, follow SDK specific docs. Firebase is highlighted here since v1-v2 difference could be confusing.

Troubleshooting

Copied!

Push notifications are not always intuitive to implement because they involve systems outside of Stream Chat with a number of moving parts. We've put together some resources on common errors and how to resolve them.

Other Push Providers

Copied!

While Stream Chat doesn't have first class integration for Push providers besides Firebase, APN, Huawei and Xiaomi, it is entirely possible to integrate with additional providers using Webhooks.