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

Retrieve number of unread items

You can retrieve the count of a user's unread messages, unread mentioned messages, or received invitations in group channels and Supergroup channels. You can use this action to display the count in the UI and prompt the user to check unread messages and invitations. This is only available for group channels and Supergroup channels.

To get the count, create a UnreadItemCountParams instance by setting UnreadItemKey in keys. Then pass it to the getUnreadItemCount() method.

The following table lists acceptable values for UnreadItemKey.

ValueDescription

GROUP_CHANNEL_INVITATION_COUNT

The number of invitations the user has received for all group channels and Supergroup channels.

GROUP_CHANNEL_UNREAD_MENTION_COUNT

The number of messages the user was mentioned but hasn't read in all group channels and Supergroup channels.

GROUP_CHANNEL_UNREAD_MESSAGE_COUNT

The number of messages the user hasn't read in all group channels and Supergroup channels.

NONSUPER_INVITATION_COUNT

The number of invitations the user has received for all group channels channels.

NONSUPER_UNREAD_MENTION_COUNT

The number of messages the user was mentioned but hasn't read in all group channels.

NONSUPER_UNREAD_MESSAGE_COUNT

The number of messages the user hasn't read in all group channels channels.

SUPER_INVITATION_COUNT

The number of invitations the user has received for all Supergroup channels.

SUPER_UNREAD_MENTION_COUNT

The number of messages the user was mentioned but hasn't read in all Supergroup channels.

SUPER_UNREAD_MESSAGE_COUNT

The number of messages the user hasn't read in all Supergroup channels.

const params: UnreadItemCountParams = {
    keys: [
        UnreadItemKey.GROUP_CHANNEL_UNREAD_MENTION_COUNT,
        UnreadItemKey.GROUP_CHANNEL_UNREAD_MESSAGE_COUNT,
    ],
};
const unreadItemCount: UnreadItemCount = await sb.getUnreadItemCount(params);