Push notifications

Stream sends push notifications through Firebase Cloud Messaging (FCM), Apple Push Notification service (APN), Huawei Push and Xiaomi Push. Push providers, device registration and push preferences work the same way across products and are managed with the same APIs. Each product decides which events send a push and what the notification contains; those rules and templates are documented with each product.

The Stream API doesn't support web push notifications. If you're building a mobile application using JavaScript technologies, you can set up mobile push notifications using the supported providers.

Setting Up Push

Push is available to Stream integrations running in a mobile environment. Setting it up takes three steps:

  1. Configure a push provider on the Stream Dashboard
  2. Add client-side integration for your chosen provider in your app
  3. Register user devices with Stream's API

The client-side steps depend on which SDK you are using; follow the push notification guide in your SDK's documentation.

Push Providers

A push provider is a configuration of a push API with one of four types: APN, Firebase, Huawei and Xiaomi. Chat supports all four provider types. Activity Feeds supports Firebase and APN.

Multiple providers can be added to the same Stream application to support:

  • Different builds of the same application, such as prod and staging or regular and admin
  • Different target platforms, such as starting with React Native and adapting native Android and iOS SDKs along the way
  • Multi-tenant applications, where different customers need different configurations

While Stream 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.

Management of push providers with the endpoints below only works if your app is upgraded to v2 or v3. Otherwise, the update app settings endpoint must be used for a single provider config per type (APN, Firebase, Huawei, Xiaomi).

Dashboard Configuration

  1. Navigate to your Stream Dashboard
  2. Select your application
  3. Go to the Push Notifications section
  4. Click New Configuration and select your provider
  5. Upload your credentials

Push Notifications Dashboard Menu

Firebase requires a service account key 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 it in the Firebase credentials field. A sample service account JSON:

{
  "type": "service_account",
  "project_id": "your-project-id",
  "private_key_id": "key-id",
  "private_key": "-----BEGIN PRIVATE KEY-----\nYOUR_PRIVATE_KEY\n-----END PRIVATE KEY-----\n",
  "client_email": "firebase-adminsdk-xxxxx@your-project.iam.gserviceaccount.com",
  "client_id": "client-id",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token"
}

APN requires an Apple Developer account and an authentication key or certificate:

Field NameDescription
NameDescriptive name for this configuration
Bundle IDYour iOS app's bundle identifier
Team IDYour Apple Developer Team ID
Key IDYour APNs authentication key ID
Authentication KeyYour .p8 private key file

Upsert a Push Provider

In the same endpoint, a new config can be created or updated.

Up to 25 push providers can be added to a single application.

If the authentication information is updated, linked devices might be invalidated in the next push message sent retry.

const pushProviderConfig = {
  name: "my-custom-name",
  type: "firebase",
  firebase_credentials: "my-service-account-information",
};

client.upsertPushProvider(pushProviderConfig);

List Push Providers

client.listPushProviders();

Delete a Push Provider

const pushProviderID = {
  type: "apn or firebase or huawei or xiaomi",
  name: "your given custom name while creating",
};

client.deletePushProvider(pushProviderID);

Linking Devices to Providers

By default, adding a device doesn't require a push provider linking due to backward compatibility where old configurations don't have a name, so their names are empty.

  • If the configuration name is not provided when adding a device, devices will be matched with configurations according to only their types.

  • If the configuration name is provided, but invalid, the request will fail with a bad request error.

When devices are added, they can be linked to a provider to inherit their configuration.

const pushToken = "your client side generated device token to receive pushes";
const pushProviderType = "apn or firebase or huawei or xiaomi";
const userId = "your user id for server side calls";
const pushProviderName =
  "the name of the provider you created while configuring your app";

client.addDevice(pushToken, pushProviderType, userId, pushProviderName);

Single-Provider Configuration

If you're not interested in multi-bundle support, you can leverage the updateAppSettings endpoint to add push configuration for a single APN, Firebase, Huawei or Xiaomi provider.

// this configuration is same with upsert push provider
// except type is inherent and naming is missing so it's set to empty string
const firebase_config = {
  credentials_json: "my-service-account-information",
};

client.updateAppSettings({ firebase_config });

Registering Devices

Once your app has enabled push notifications, use the APIs to register user devices such as iPhones and Android phones.

Each user has a limit of 25 unique devices. Once this limit is reached, the oldest device will be removed and replaced by the new device.

Device Parameters

NameTypeDescriptionDefaultOptional
idstringThe device ID (push token provided by the push provider)-
user_idstringThe user ID for this device-
push_providerstringThe push provider for this device: APN, Firebase, Huawei or Xiaomi-
disabledbooleanSet if the device is disabledfalse
disabled_reasonstringExplanation if the device is disabled-
push_provider_namestringThe push provider name for multi-bundle configurations-

Register a Device

Registering a device associates it with a user and tells the push provider to deliver notifications to the device.

Register the user's device for push notifications once your user is successfully connected.

Multi-bundle configurations require that you specify a push_provider_name when registering a device that corresponds to the name of the push configuration that you've set up in the dashboard or via the API.

await client.createDevice({
  id: "<push token>",
  push_provider: "apn",
  push_provider_name: "production-ios",
  user_id: "user_id",
});

List Devices

Provides a list of all devices associated with a user.

const devices = await client.listDevices({ user_id: "<user_id>" });

Remove a Device

Removing a device stops further push notifications to it.

await client.deleteDevice({
  id: "<device id>",
});

Push Preferences

Users control which notifications they receive with push preferences, set through the same endpoint across products. Preferences use a per-product level field: chat_level and call_level for Chat and Video, feeds_level for Activity Feeds. All of them support temporarily disabling push until a timestamp with disabled_until.

Each product documents its own preference levels and granular per-event controls:

What Each Product Configures

Which events send a push, the delivery rules and the notification templates are configured per product:

Troubleshooting

Push notifications are not always intuitive to implement because they involve systems outside of Stream with a number of moving parts. If push isn't arriving:

  1. Check your push configuration in the Stream Dashboard
  2. Verify your device token is valid and current
  3. Ensure proper permissions are granted for notifications
  4. Check the push logs in the Stream Dashboard for error messages
  5. Test with different devices to isolate the issue

Chat documents common errors and how to resolve them.