Skip to main content
Threaded messages (or threads) are messages started from a particular parent message. Each thread is attached to a parent message.
Available via: SDK | REST API | UI Kits

Send Message in a Thread

As mentioned in the Send a Message section, you can send a message to a User or a Group by mentioning the receiver (uid/guid) and receiverType(user/group). A message can be categorized as:
  1. Text Message
  2. Media Message
  3. Custom Message
  4. Interactive Message
Set the parentMessageId on the message object to indicate which thread the message belongs to. The id specified in the parentMessageId parameter maps the message sent to the particular thread. Any message type — TextMessage, MediaMessage, CustomMessage, or Interactive Message — can be sent in a thread.
TextMessage Parameters:
On Success — A TextMessage object containing all details of the sent threaded message:TextMessage Object:
sender Object:
receiver Object:
The above snippet shows how a message with the text “Hello” can be sent in the thread with parentMessageId 103. Similarly, using the parentMessageId parameter, Media and Custom Messages can be sent in threads too.

Receiving Real-Time Messages

The procedure to receive real-time messages is exactly the same as mentioned in the Receive Messages section. Use the MessageListener class to listen for incoming thread messages. Check if the received message belongs to the active thread using the parentMessageId field.
Always remove message listeners when they’re no longer needed (e.g., in the dispose() method). Failing to remove listeners can cause memory leaks and duplicate event handling.

Fetch all the messages for any particular thread.

Use MessagesRequestBuilder with parentMessageId to fetch messages belonging to a specific thread. Call fetchPrevious() to get messages (max 100 per request), returned as BaseMessage objects. Call fetchPrevious() again on the same object to get the next set. MessagesRequestBuilder Parameters:
On Success — A List<BaseMessage> containing the fetched thread messages (each item is a BaseMessage object):BaseMessage Object:
sender Object:
receiver Object:

Avoid Threaded Messages in User/Group Conversations

While fetching messages for normal user/group conversations using the MessagesRequest, the threaded messages by default will be a part of the list of messages received. Use hideReplies = true on the MessagesRequestBuilder to exclude threaded messages from the list.
On Success — A List<BaseMessage> containing the fetched messages excluding threaded replies (each item is a BaseMessage object):BaseMessage Object:
sender Object:
receiver Object:
The response is a list of BaseMessage objects, excluding any messages that are replies within a thread. Only top-level messages in the conversation are returned.

Next Steps

Send Messages

Learn how to send text, media, and custom messages

Receive Messages

Handle incoming messages in real-time

Reactions

Add emoji reactions to messages

Message Structure

Understand message types and hierarchy