Message count in group channel with javascript sdk

How can I get the message count of a group channel with the javascript sdk?


First off, welcome to the Sendbird community! We’re glad you’re here. Just to clarify, are you looking for total message count, unread message count or something else?


Hey Tyler, thank you :slight_smile:

Looking for the total message count

To get the total message count, you could grab the channel, generate a list of messages and grab the count of that list.

That could look something like this:

sb.GroupChannel.getChannel(channelURL, (groupChannel, error) => {
  const listQuery = groupChannel.createPreviousMessageListQuery();
  listQuery.load((messages, error) => {
      const totalMessageCount = messages.length

      type: GET_MESSAGES,
      payload: messages,

Doesn’t the list query have a limit max of 100?
Fetching every single message in the channel would also be expensive. Is there no way to only ask for the count?

You are correct that the SDK has a limit of 100. The Platform API does have a bit of a larger limit, but it would still be limited. This isn’t a data point that we track currently, and thus any solution would ultimately be clunky and expensive.


One of my colleague pointed out that while the Javascript SDK does not provide this information, the Platform API does:

Is there a specific purpose for needing the message count of each channel?

Yeah, I would like to cache my messages to redux and use the total channel message count to tell me if the cache has gotten out of sync with your servers.


It sounds like messageChangeLogs would be better suited for what you’re looking to accomplish. Have you taken a look at that yet?