Skip to main content
Android
iOS
Web
Windows
Unity
Flutter
React Native

Set DND mode

To optimize the user experience when dealing with a large number of push notifications, Chat SDK provides fine-grained settings for push notifications and do not disturb mode at the app and conversation levels.

Push notification settings

ParameterDescriptionAppOne-to-one and group chats
ALLReceive push notifications for all offline messages.
MENTION_ONLYReceive push notifications only for mentions. < br />This parameter is recommended for group chats. To mention one or more users, pass "em_at_list": [ "user1", "user2" ... ] to the ext field when creating a message. To mention all, pass "em_at_list": "all" to this field.
NONEDo not receive push notifications for offline messages.

The push notification setting at the conversation level takes precedence over the setting at the app level. For conversations where the push notification setting is not configured, the app setting is used by default.

For example, suppose the push notifications for the app are set to MENTION_ONLY and the push notifications for a given conversation are set to ALL. A user will receive all push notifications from that conversation, but for all other conversations, they will only receive push notifications for messages that mention them.

You can specify the DND time period and duration at the app level, and Chat will not send offline push notifications during these two periods. If both the DND time and DND duration are set, the DND mode will take effect for the sum of the two.

The following table describes the DND time settings:

SettingDescriptionAppOne-to-one and group chats
SILENT_MODE_INTERVALThe time period for turning on the DND mode, in the H:MH:M format, using the 24-hour system and accurate to the minute. For example, 8:30-10:0. The range of hours and minutes in the start time and end time is [0,23] and [0,59], respectively. The DND mode is set in the following way:
  • After the start time and end time are set, the DND mode is triggered every day. For example, if the time period is set to 8:0-10:0, the DND mode is effective from 8:00 to 10:00 every day. If you set the start time to 8:0 and the end time to 12:0 at 11:00, the DND mode is effective from 11:00 to 12:00 on the same day, and from 8:00 to 12:00 every day thereafter.
  • If the start time and end time are the same, the DND mode is effective all day. However, if it is set to 0:0-0:0, the DND mode will be turned off.
  • If the end time is earlier than the start time, the DND mode will take effect from the start time of each day to the end time of the next day. For example, if the start time is 10:0 and the end time is 8:0, the DND mode will take effect from 10:00 on that day to 8:00 on the next day.
  • The DND mode can only be enabled during a specified time period each day. Multiple DND time periods are not supported. The new setting will override the previous setting.
  • If both this parameter and SILENT_MODE_DURATION are set, the DND mode will be in effect during both time periods on the day. For example, if SILENT_MODE_INTERVAL is set to 8:0-10:0 and SILENT_MODE_DURATION is set to 240 minutes (4 hours) at 8:00 am, the app will be in DND mode from 8:00-12:00 on that day and from 8:00-10:00 every day thereafter.
SILENT_MODE_DURATIONThe DND duration, in minutes. The value range of the DND duration is [0,10080], where 0 means the parameter is invalid and 10080 means the DND mode lasts for 7 days. < br /> Unlike the setting of the DND time period, which takes effect every day, this parameter is valid once. It takes effect immediately after setting. For example, if you set the app-level SILENT_MODE_DURATION to 240 minutes (4 hours) at 8:00 am, the app will be in DND mode from 8:00 to 12:00 on the same day. < br /> If both this parameter and SILENT_MODE_INTERVAL are set, the DND mode will be effective during both time periods on the same day. For example, if the app-level SILENT_MODE_INTERVAL is set to 8:00-10:00 at 8:00 am and the DND duration is set to 240 minutes (4 hours), the app will be in DND mode from 8:00-12:00 now and from 8:00-10:00 every day thereafter.

If you need to push messages to specific users during the DND period or effective time, set Force push.

For the app and all conversations in the app, the DND setting takes precedence over the push notification setting. For example, suppose a user specifies a DND time period at the app level and sets push notifications to ALL. The app enters the DND mode during the specified time period, and the user will not receive any push notifications.

Alternatively, suppose a conversation is assigned a DND time period. The app does not have any DND settings and its push notifications are set to ALL. During the specified DND time period, the user will not receive any push notifications from this conversation, while push notifications from all other conversations will remain unchanged.

Set up push notifications for the app

Call setSilentModeForAll to set app-level push notifications. Set push notifications and DND mode by specifying the SilentModeParam field, as shown in the following example:


_11
// Set push notification mode to `MENTION_ONLY`.
_11
SilentModeParam param = new SilentModeParam ( SilentModeParam . SilentModeParamType . REMIND_TYPE )
_11
.setRemindType(PushManager.PushRemindType.MENTION_ONLY);
_11
// Set the offline push do not disturb timer to 15 minutes.
_11
SilentModeParam param = new SilentModeParam ( SilentModeParam . SilentModeParamType . SILENT_MODE_DURATION )
_11
.setSilentModeDuration(15);
_11
// Set the do not disturb time period for offline push to 8:30 to 15:00.
_11
SilentModeParam param = new SilentModeParam ( SilentModeParam . SilentModeParamType . SILENT_MODE_INTERVAL )
_11
.setSilentModeInterval(new SilentModeTime(8, 30), new SilentModeTime(15, 0));
_11
// Set up offline push notifications for the app.
_11
ChatClient.getInstance().pushManager().setSilentModeForAll(param, new ValueCallBack<SilentModeResult>(){});

Get the push notification settings of the app

Call getSilentModeForAll to get the app-level push notification settings, as shown in the following example:


_19
ChatClient.getInstance().pushManager().getSilentModeForAll(new ValueCallBack<SilentModeResult>(){
_19
@Override
_19
public void onSuccess(SilentModeResult result) {
_19
// Get the push notification method settings of the app.
_19
PushManager.PushRemindType remindType = result.getRemindType();
_19
// Get the Unix timestamp of the app's offline push Do Not Disturb expiration.
_19
long timestamp = result.getExpireTimestamp();
_19
// Get the start time of the app's offline push do not disturb time period.
_19
SilentModeTime startTime = result.getSilentModeStartTime();
_19
startTime . getHour(); // The hour in the start time of the do not disturb time period.
_19
startTime . getMinute(); // The number of minutes in the start time of the do not disturb time period.
_19
// Get the end time of the app's offline push do not disturb time period.
_19
SilentModeTime endTime = result.getSilentModeEndTime();
_19
endTime . getHour(); // The number of hours in the end time of the do not disturb period.
_19
endTime . getMinute(); // The number of minutes in the end time of the do not disturb time period.
_19
}
_19
@Override
_19
public void onError(int error, String errorMsg) {}
_19
});

Set push notifications for a single conversation

Call setSilentModeForConversation to set push notifications for a specified conversation. Configure push notifications and the DND mode by specifying the SilentModeParam field, as shown in the following example:


_9
// Set push notification mode to `MENTION_ONLY`.
_9
SilentModeParam param = new SilentModeParam ( SilentModeParam . SilentModeParamType . REMIND_TYPE )
_9
.setRemindType(PushManager.PushRemindType.MENTION_ONLY);
_9
_9
// Set the offline push do not disturb timer to 15 minutes.
_9
SilentModeParam param = new SilentModeParam ( SilentModeParam . SilentModeParamType . SILENT_MODE_DURATION )
_9
.setSilentDuration(15);
_9
// Set the offline push do not disturb mode for the conversation. Currently, it does not support setting the do not disturb time period for the conversation.
_9
ChatClient.getInstance().pushManager().setSilentModeForConversation(conversationId, conversationType, param, new ValueCallBack<SilentModeResult>(){});

Get push notification settings for a single conversation

Call getSilentModeForConversation to get the push notification settings for a specified conversation, as shown in the following code example:


_16
ChatClient.getInstance().pushManager().getSilentModeForConversation(conversationId, conversationType, new ValueCallBack<SilentModeResult>(){
_16
@Override
_16
public void onSuccess(SilentModeResult result) {
_16
// Get whether the push notification method is set for the specified conversation.
_16
boolean enable = result.isConversationRemindTypeEnabled();
_16
// Check if the conversation has push notifications set.
_16
if(enable){
_16
// Get the push notification method for the conversation.
_16
PushManager.PushRemindType remindType = result.getRemindType();
_16
}
_16
// Get the offline push Do Not Disturb expiration Unix timestamp of the conversation.
_16
long timestamp = result.getExpireTimestamp();
_16
}
_16
@Override
_16
public void onError(int error, String errorMsg) {}
_16
});

Get push notification settings for multiple conversations

You can get push notification settings for up to 20 conversations in each call. If a conversation uses app settings or its push notification settings have expired, the returned dictionary does not contain such conversation.

Call getSilentModeForConversations to get the push notification settings for multiple conversations, as shown in the following sample code:


_6
ChatClient.getInstance().pushManager().getSilentModeForConversations(conversationList, new ValueCallBack<Map<String, SilentModeResult>>(){
_6
@Override
_6
public void onSuccess(Map<String, SilentModeResult> value) {}
_6
@Override
_6
public void onError(int error, String errorMsg) {}
_6
});

Clear push notification settings for a single conversation

Call clearRemindTypeForConversation to clear the push notification type for a specific conversation. After clearing, the conversation will use the app's settings by default.

The following code example shows how to clear a conversation's push notifications:


_1
ChatClient.getInstance().pushManager().clearRemindTypeForConversation(conversationId, conversationType, new CallBack(){});

vundefined