Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Home
/
Chat
/
JavaScript
/
Notifications
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

Notification preferences

By registering or unregistering the current user's registration token to the Sendbird server as below, you can turn push notifications on or off in the user's app. The registration and unregistration methods in the code below should be called after a user has established a connection with the Sendbird server via the connect() method.

Note: Push notifications are only supported in group channels.

const setPushNotification = (enable: boolean, os: 'ios' | 'android') => {
    if (enable) {
        if (os === 'ios') {
            await sb.registerAPNSPushTokenForCurrentUser(TOKEN);
        } else {
            await sb.registerFCMPushTokenForCurrentUser(TOKEN);
        }
    } else {
        if (os === 'ios') {
            await sb.unregisterAPNSPushTokenForCurrentUser(TOKEN);
        } else {
            await sb.unregisterFCMPushTokenForCurrentUser(TOKEN);
        }
    }
}

Push trigger options allow users to configure when to receive notification messages as well as what type of messages will trigger notification messages. The following three options are provided.

List of push trigger options

OptionDescription

all

When disconnected from the Sendbird server, the current user receives notifications for all new messages including messages the user has been mentioned in.

mention_only

When disconnected from the Sendbird server, the current user only receives notifications for messages the user has been mentioned in.

off

The current user doesn't receive any notifications.

await sb.setPushTriggerOption('mention_only');

Push trigger options for channel also allow users to configure the trigger for notification messages as well as turn notifications on or off for each channel. The following four options are provided.

List of push trigger options for channel

OptionDescription

default

The current user’s push notification trigger settings are automatically applied to the channel. This is the default setting.

all

When disconnected from the Sendbird server, the current user receives notifications for all new messages in the channel including messages the user has been mentioned in.

mention_only

When disconnected from the Sendbird server, the current user only receives notifications for messages in the channel the user has been mentioned in.

off

The current user doesn't receive any notifications in the channel.

await groupChannel.setMyPushTriggerOption('default');

If you want to routinely turn off push notification on the current user's client app according to a specified schedule, use our Do Not Disturb feature like the following.

Note: Do Not Disturb can also be set for a user with our platform API's update push preferences action.

await sb.setDoNotDisturb(true, START_HOUR, START_MIN, END_HOUR, END_MIN, 'Asia/Seoul');

To snooze notification messages for a specific period of time, use our snooze feature like the following.

Note: snooze can also be set for a user with our platform API's update push preferences action.

await sb.setSnoozePeriod(true, START_TS, END_TS);