How to use Chat SDK for Notifications
This guide outlines the steps to integrate Sendbird Chat SDK for Sendbird Notifications, from initialization to displaying notifications in a channel. Follow the instructions below to implement essential functionalities for Notifications. Sendbird Notifications is currently supported by Chat SDK on these platforms:
- Chat SDK for iOS
- Chat SDK for Android
- Chat SDK for Flutter
Note: Before we dive into the client side implementation of Sendbird Notifications, it is assumed you have already installed the Chat SDK. If not, install the Chat SDK by following this guide.
Step 1 Initialize the SDK
First, initialize Sendbird Chat SDK. This tells the SDK which application it will communicate with as well as which features it will support.
Step 2 Implement session handlers
In order to ensure that a user's notifications are properly secured, Sendbird strongly recommends that our customers utilize
sessionTokens in order for users to connect via the SDK. For this reason, you will need to implement session handlers in order to handle expiring or revoked
For data security, Sendbird strongly recommends our customers do not directly call the Platform APIs from a client-facing application. Due to this reason, you should implement a service to call your backend to refresh the users token.
Note: Session handlers must be set prior to authentication in order for them to function correctly.
Step 3 Authentication
Now that we've initialized our application and registered our session handlers, we can now authenticate to the Sendbird servers through the
authenticateFeed method on the SDK.
Step 4 Retrieve a feed channel
In order to fetch a list of notifications, first fetch the channel that the notifications belong to. We can achieve this in one of two ways. If we know the
channel_url of the channel we want to load, we can fetch the channel directly. Otherwise, we can fetch a list of channels first.
Retrieve a channel by URL
Retrieve a list of channels
Step 5 Create a notification collection
Once a feed channel is retrieved, you can create a
NotificationCollection. The collection is an instance that allows you to swiftly create a Notification Channel view that contains all of the necessary data.
In order to keep your collection up to date, you should utilize the
refreshNotificationCollections to check for new notifications or channel updates. It's recommended that you refresh the collection whenever the application goes from the background to the foreground.
Step 6 Render a notification
The final step is to render a Notification. Each Notification will contain a
notificationData object that contains all the variable information about a single notification.
notificationData contains the following information:
The sub-category of the notification. You can utilize this as a filter on the UI.
The unique key to a template. You can set the key when creating a template on the dashboard.
Array of strings
The tags associated with the template. To learn how to use tags, see the Tags guide.
Object of key-value pairs
The key-value pairs of the variables you've set to the template. You can edit the variables through Template editor on the dashboard.