Search code examples
slackslack-api

Is it possible to know the number of unread Slack messages a user has with the Slack API?


I'm building a messaging integration with Slack and a client. I need to show the badges on the corresponding conversations when the users logs in to the client to show the client how many unread messages it has.

I know that the channels.history method had the unreads parameter which would return as part of the response the amount of unread messages according to the user token, but that method is deprecated and my app is too new to use it.

I'm using the conversations.history now to retrieve the messages which is what slack suggest to use instead of the deprecated method channel.history, but this new method doesn't have that parameter and doesn't show any info regarding the amount of unread messages in the conversation.

As my app is a new one and not a classic one, I cannot use the RTM API.

I'm also subscribed to the message events so that I know when a new message was posted.

My issue is that I need to know how many new messages were sent to the user while he was not logged in.

Is there any way to get that info?


Solution

  • Unread count is in conversations.info method, not in conversations.history. There in unread_count and unread_count_display property in reponse. Documentation is here.