Message sent via API appears as "unread"

We have a service that sends automated messages to group channels via API, as a default user, and with the “mark_as_read” = “true”, but in the JS Chat SDK these messages appear in the “unread_messages” filter (“channelListQuery” - “unreadChannelFilter”) and I can’t understand why

Hi @Nuno_Campos,

Can you confirm what type of message you’re sending? Is it an ADMM or a MESG? Additionally, are you seeing the unread count on the recipient?

Hello @Tyler,
It’s type “MESG” and the unread count doesn’t appear for these messages.

(Btw, I’m viewing the page as the “default user”, the same user used to send the message via API.
For the other users in the group It’s fine)

@Nuno_Campos,

Just to ensure I’m on the same page, is. the message appearing in the filter for the default user or for the recipient?

I’m viewing the page as the “default user”, the same user used to send the message via API

Would you mind DMing me just a quick example cURL request you’re making as well as how you’re checking? I want to reproduce this so I can investigate more thoroughly.

sure, will do that, thanks

Hi Tyler, did you had the oportunity to check the code?
thanks

Hi again @Tyler,
I’m sorry, I tried different approaches but still can’t figure it out why this happens… I think this could be an issue in your end. If you could spend a couple of minutes checking this problem we will be really appreciated. Thanks!

Hi @Nuno_Campos,

My apologies. Let me try and look at this today for you.

1 Like

Hi @Tyler, any news? thanks

Hi @Nuno_Campos,

I apologize for my response. I’ve clearly dropped the ball here. I just want to clarify a few points because as I’m reading on this, I’m slightly confused.

You’re sending messages of messageType MESG from the Default User. You’re sending those messages with mark_as_read = true.

Are the messages showing up as unread for Default User or for the other users in the channel?

We have 2 tabs, one for “unread_message” and other for “all”,
the problem is, for the “Default User”, if we have the “unread_message” tab opened, the messages sent via API (as the “Default User”) appear there, almost instantly, and they shouldn’t

(For the other users the messages appear as unread, that’s fine)

And the query you utilize for the unread_message tab is the one you sent me via DM correct?

yes:

setQueries({
            channelListQuery: {     // used in channel list
                limit: 20,
                includeEmpty: false,
                order: orderQuery,
                unreadChannelFilter: unreadQuery,
                nicknameContainsFilter: usernameQuery,
                userIdsIncludeFilter: userIdQuery ? [userIdQuery] : [],
            },
            applicationUserListQuery: {     // used in "create new chat"
                limit: 100,
            }
        })

Hi @Nuno_Campos,

I’m unable to recreate this problem. I have a user, testUser77. When I send a message via the Platform API that has a body of:

{
    "user_id": "testUser77",
    "message_type": "MESG",
    "message": "test02",
    "mark_as_read": true
}

And then I do a query for the users unread_channels using the Platform API and the my_group_channels endpoint with a query of my_group_channels?unread_filter=unread_message. Am I interpreting how you’re pulling in the channels incorrectly?

Also, it sounds like a channelHandler may be at play if you’re seeing the channelList update instantly. Could you provide me some context about how manage your channelList on the client side?

Hi @Tyler,
(I’m sorry for the late response, we’ve been working on other issues an this one got delayed)
I’ve made 2 recordings showing the behavior, I think it’s easier to understand.
We are using the Sendbird UIKit React SDK as base, with some custom components.

So in our case, “Nuno” is the app user, and “Vet” is the browser user:

Video 1 - Regular case, “Nuno” sends a message, and it appears as “unread” for “Vet”, everything is ok.

Video 2 - Issue case, first “Vet” sends a message, all good, but then a message is sent via “API” as the “Vet”, and it instantly appears in the “unread messages”, but as read! (it doesn’t have the unread counter in orange), and if we update the query (via the buttons), it no longer appears as “unread”

So this issue should be in sendbird’s side, I don’t know if it’s an API or UIKit bug, I hope you could figure it out!

Thanks!

Hi @Nuno_Campos,

Couple of things I notice in the second video and I want to make sure, I understand what we’re seeing.

  1. When the vet sends a message, I do not expect the channel to show up in the unread_messages section at all. Since the user can’t unread their own message. So that to me looks correct.
  2. When the vet sends a message via the Platform API, I still would not expect the message to show up in the unread_message list nor would I expect the unread count to be updated.

I believe I know why number 2 is happening. Essentially, when the SDK receives a new message over the WebSocket, it triggers the onMessageReceived event handler. When the channel that received the message does not appear in the current state, it’s added. This explains why you’re seeing the message show up but not seeing the unread count populate.

When you navigate to all_messages and back, you re-query for the unread channels and since the channel never contained an unread message, it is empty.

So this isn’t really an issue around unread vs read, its more an issue around having multiple ChannelList components and having them operate differently from the way the event handlers manipulate them.

Currently, we don’t support a way to create different handler logic for multiple components of the same type.

Thanks @Tyler for the quick response,

When the vet sends a message via the Platform API, I still would not expect the message to show up in the unread_message list nor would I expect the unread count to be updated

exactly, that’s the issue here.

its more an issue around having multiple ChannelList components and having them operate differently from the way the event handlers manipulate them.

I only have one ChannelList component, that has the “queries” property that is updated dynamically via the “all/unread” buttons…

So is there anything we can do?

Hi @Nuno_Campos ,

Thank you for that further clarification on your ChannelList component. While it’s actually just a singular component the end result is still the same. The channelHandler is still inserting the “missing” channel into the component.

In its current form, there is no way to address this in the official release. I’ll check in with our Engineering team to see if there is any plan to allow modification to the handler logic.

You could address this by utilizing the open sourced version of the UIKit which would allow you to modify that behavior.

1 Like