Send message with parent message id is not working

hi sendbird.
i am using sdk 3.0.143.

when i send message via method sendUserMessage in open channel, i did pass UserMessageParams with setParentMessageId({message id}).

while the result from getMessagesByTimestamp with shouldIncludeThreadInfo = true and shouldIncludeReplies = true in MessageListParams has no parentMessageId parameter.

May I know how to reply message and retrieve the reply message id back?

Hi @darylsze If you sent the user message with parentId, it meant a reply message.

And then the reply message has to request via BaseMessage.getThreadedMessagesByTimestamp not BaseChannel.getMessagesByTimestamp.

If you request BaseMessage.getThreadedMessagesByTimestamp or BaseChannel.getMessagesByMessageId, parentMessageId will be included in the responsed message.

BaseChannel.getMessagesByMessageId(long messageId, MessageListParams params, final GetMessagesHandler handler)

or

BaseMessage.getThreadedMessagesByTimestamp(long ts, ThreadMessageListParams params, final GetThreadedMessagesHandler handler)

@darylsze Hi.

Aside from @LeoShin 's excellent reply, I also want to mention that message threading and the use of message replies is an early access program feature of Sendbird.

If your organization is not in the early access program, then message threading may not be turned on for your application. Please can you DM me you application_id and I will follow up regarding the early access program for message threading and check if you have it turned on.

Thank you both of your great replies.

Apart from thread or replies which is a early access feature, I guess others using sendbird sdk in early version used data field to store whole message being replied in json, so next time client side fetch the messages, the reply message and corelated message are both obtained.

While this approach has potential problem – that there will be two source of truth, and if one updated the original message, the copied one in data field will be out of sync.

I did use different sdk provider before, one of the approach suggested is putting parent message id (the messgae being replied) into the reply message. Then in future fetch, client side groups all parent message id(s) and query the actual detailed messages with those id(s). This ensure the source of truth.

May I know what’s sendbird suggestion?

Hi @darylsze,

I left an answer on your other question here.
Message thread works exactly the way you described.

For sending a reply, we allow you to set the parentMessageId in UserMessageParams, FileMessageParams.

For fetching reply messages, we have parentMessageObject.getThreadedMessagesByTimestamp which will fetch all reply messages of a message.
If you only have a parent message ID, not an object, you can retrieve the parent message object first, using
BaseMessage.getMessage(MessageRetrievalParams, GetMessageHandler),
then use the message object to get reply messages.

Thank you hoons for the reply.

By using getThreadedMessagesByTimestamp, we can exchange the message details through parent message id, but this api exchange 1 message at a time only.

Let’s imagine I have 50 messages in bulk, in which 10 of them are reply messages. So I take all of them out, and compose those 10 parent message id(s) as array, and call the getThreadedMessagesByTimestamp 10 times in parallel. This creates 10 times HTTP overhead and bandwidth.

According to LeoShin, sendbird currently doesn’t have 'query messages by array id`, so this operation seems unavoidable.

In other word, sendbird support slack alike messager than whatsapp alike, am I correct?

@darylsze

What you point out is correct. However, when storing the parent message in the data field of the child there is the additional overhead of passing the message as a push notification. This leads to a problem when as push notifications as a whole need to be under 4kb. Although, Sendbird does have the ability to turn off including the data field in push notifications.

Regarding the edit part and there being stale data on the child, this is also true, and would mean some additional message updating to keep things in sync as you describe.

Please do DM me you app id if you are interested in the early access programme.

@Jason
Thank you Jason.

We are thinking implement the query messages by array of message id by our own. Before that, is it possible for Sendbird to implement this api btw? thanks!

Hi @darylsze

I do not recommend the approach you mention regarding an array of message ids. I think you would be better to join the message replied early access program. The problem with rolling your own is that it can quickly be coming expensive as you would be calling messages one by one. Where as Sendbird’s own message reply service is optimized to fetch the parent’s child messages.