Skip to main content
Key properties: uid, guid, limit, categories, types, tags, unread, parentMessageId, messageId, timestamp, hideReplies, hideDeleted, hideQuotedMessages, searchKeyword, updatedAfter, updatesOnly, hideMessagesFromBlockedUsers, withTags, hasMentions, hasLinks, hasAttachments, hasReactions, mentionedUids, attachmentTypes, withParent
The MessagesRequest class helps you fetch messages based on various parameters — returning BaseMessage objects that can be TextMessage, MediaMessage, CustomMessage, Action, or Call. It uses the Builder design pattern via MessagesRequestBuilder. To fetch messages:
  1. Create a MessagesRequestBuilder object
  2. Set your desired parameters
  3. Call build() to get a MessagesRequest object
  4. Call fetchNext() or fetchPrevious() to retrieve messages
Messages are paginated with a maximum of 100 per request. Calling fetchPrevious()/fetchNext() repeatedly on the same object gets subsequent pages.

MessagesRequestBuilder Parameters

Number of messages fetched

In other words, how do I set the number of messages fetched in a single iteration To achieve this, you can use the limit property. This takes an integer value and informs the SDK to fetch the specified number of messages in one iteration. The maximum number of messages that can be fetched in one go is 100.

Messages for a user conversation

In other words, how do I fetch messages between me and any user Use the uid property to fetch messages between the logged-in user and a specific user.

Messages for a group conversation

In other words, how do I fetch messages for any group conversation Use the guid property to fetch messages from a group. The logged-in user must be a member of the group.
If neither uid nor guid is set, all messages for the logged-in user across all conversations will be fetched. All parameters below can be combined with uid or guid.

Messages before/after a message

In other words, how do I fetch messages before or after a particular message Use the messageId property. This provides messages only after/before the message-id based on if fetchNext() or fetchPrevious() is called.
This property can be used along with uid or guid to fetch messages after/before any specific message-id for a particular user/group conversation.

Messages before/after a given time

In other words, how do I fetch messages before or after a particular date or time Use the timestamp property. This takes a DateTime value and provides messages only after/before the timestamp based on if fetchNext() or fetchPrevious() is called.
This property can be used along with uid or guid to fetch messages after/before any specific date or time for a particular user/group conversation.

Unread messages

In other words, how do I fetch unread messages Use the unread property set to true to return just the unread messages.
Combine with guid or uid to fetch unread messages for a specific conversation.

Exclude messages from blocked users

In other words, how do I fetch messages excluding the messages from the users I have blocked Use the hideMessagesFromBlockedUsers property. If set to true, messages from users blocked by the logged-in user will be excluded. Default is false.
This also works in group conversations where both users are members.

Updated and received messages

In other words, how do I fetch messages that have been received or updated after a particular date or time Use the updatedAfter property with a DateTime value to return all messages that have been updated and the ones that have been sent/received after the specified time. Updated messages include those marked as read/delivered, edited, or deleted.
Useful for syncing messages with a local database — fetch only what’s changed since your last sync.

Updated messages only

In other words, how do I fetch messages that have been updated after a particular date or time Use the updatesOnly property set to true together with updatedAfter to get just the updated messages and not the messages sent/received after the specified time. This property must be used with updatedAfter.

Messages for multiple categories

In other words, how do I fetch messages belonging to multiple categories We recommend before trying this, you refer to the Message structure and hierarchy guide to get familiar with the various categories of messages. Use the categories property with a list of category names to filter by message category.
The above snippet will help you get only the messages belonging to the message and custom category. This can also be used to disable certain categories of messages like call and action. This along with uid and guid can help display only the messages you wish to display avoiding the other category of messages.

Messages for multiple types

In other words, how do I fetch messages belonging to multiple types We recommend you refer to the Message structure and hierarchy guide to get familiar with the various types of messages before trying this out. Use the types property with a list of type names to filter by message type.
Using the above code snippet, you can fetch all the media messages. This along with uid or guid can be used to fetch media messages for any particular conversation. This can be useful in many other scenarios as well.

Messages for a specific thread

In other words, how do I fetch messages that are a part of a thread and not directly a user/group conversations Use the parentMessageId property when you have implemented threaded conversations. This will return only messages belonging to the thread with the specified parent ID.
The above code snippet returns the messages that belong to the thread with parent id 103.

Hide threaded messages in user/group conversations

In other words, how do I exclude threaded messages from the normal user/group conversations Use the hideReplies property set to true to exclude messages that belong to threads. Default is false.

Hide deleted messages in user/group conversations

In other words, how do I exclude deleted messages a user/group conversations Use the hideDeleted property set to true to exclude deleted messages. Default is false.

Hide quoted messages in user/group conversations

In other words, how do I exclude quoted messages from user/group conversations Use the hideQuotedMessages property set to true to exclude quoted messages. Default is false.

Messages by tags

In other words, how do I fetch messages belonging to specific tags Use the tags property with a list of tag names to fetch only messages with those tags.

Messages with tags

In other words, how do I fetch messages with the tags information Use the withTags property set to true to include tag information in the response. Default is false.
When withTags is set to true, each message’s tags field will be populated. In other words, as a logged-in user, how do I fetch messages that contain links? Use the hasLinks property set to true to fetch only messages containing links. Default is false.
This feature is only available with Conversation & Advanced Search. The Conversation & Advanced Search is only available in Advanced & Custom plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)

Messages with attachments

In other words, as a logged-in user, how do I fetch messages that contain attachments? Use the hasAttachments property set to true to fetch only messages with attachments (image, audio, video, or file). Default is false.
This feature is only available with Conversation & Advanced Search. The Conversation & Advanced Search is only available in Advanced & Custom plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)

Messages with reactions

In other words, as a logged-in user, how do I fetch messages that contain reactions? Use the hasReactions property set to true to fetch only messages with reactions. Default is false.
This feature is only available with Conversation & Advanced Search. The Conversation & Advanced Search is only available in Advanced & Custom plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)

Messages with mentions

In other words, as a logged-in user, how do I fetch messages that contain mentions? Use the hasMentions property set to true to fetch only messages with mentions. Default is false.
This feature is only available with Conversation & Advanced Search. The Conversation & Advanced Search is only available in Advanced & Custom plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)

Messages with particular user mentions

In other words, as a logged-in user, how do I fetch messages that mention specific users? Use the mentionedUids property with a list of UIDs to fetch messages that mention specific users.
This feature is only available with Conversation & Advanced Search. The Conversation & Advanced Search is only available in Advanced & Custom plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)

Messages with specific attachment types

In other words, as a logged-in user, how do I fetch messages with specific types of attachments? Use the attachmentTypes property with a list of attachment type values to fetch messages with specific attachment types.
This feature is only available with Conversation & Advanced Search. The Conversation & Advanced Search is only available in Advanced & Custom plans. If you’re already on one of these plans, please enable the Conversation & Advanced Search from CometChat Dashboard (Open your app, navigate to Chats -> Settings -> General Configuration)

Next Steps

Receive Messages

Handle incoming messages in real-time with listeners

Retrieve Conversations

Fetch and display conversation lists with filtering options

Message Structure

Understand message categories, types, and hierarchy

Threaded Messages

Work with message threads and replies