Skip to main content
The MessagesRequest class fetches messages based on various parameters using the Builder design pattern. 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. Call fetchPrevious()/fetchNext() repeatedly on the same object to get subsequent pages.

Filter Reference

Number of messages fetched

Set the number of messages to fetch per request using setLimit(). Maximum is 100.

Messages for a user conversation

Use setUID() to fetch messages between the logged-in user and a specific user.

Messages for a group conversation

Use setGUID() to fetch messages from a group. The logged-in user must be a member of the group.

Messages before/after a message

Use setMessageId() to fetch messages before or after a specific message ID. Use fetchNext() to get messages after, or fetchPrevious() to get messages before.
This method can be combined with setUID() or setGUID() to fetch messages around a specific message in a conversation.

Messages before/after a given time

Use setTimestamp() with a Unix timestamp to fetch messages before or after a specific time.
This method can be combined with setUID() or setGUID() to fetch messages around a specific time in a conversation.

Unread messages

Use setUnread(true) to fetch only unread messages.
This method along with setGUID() or setUID() can be used to fetch unread messages for a particular group or user conversation respectively.

Exclude messages from blocked users

Use hideMessagesFromBlockedUsers(true) to exclude messages from users you’ve blocked. Default is false.
This also works in group conversations where both users are members.

Updated and received messages

Use setUpdatedAfter() with a Unix timestamp to fetch messages that were sent or updated after a specific 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

Use updatesOnly(true) with setUpdatedAfter() to fetch only updated messages (not newly received ones). This method must be used together with setUpdatedAfter().

Messages for multiple categories

Use setCategories() with a list of category names to filter by message category. See Message structure and hierarchy for available categories.
The above snippet fetches only messages in the message and custom categories. Use this to exclude categories like call and action.

Messages for multiple types

Use setTypes() with a list of type names to filter by message type. See Message structure and hierarchy for available types.
The above snippet fetches all media messages (image, video, audio, file).

Messages for a specific thread

Use setParentMessageId() to fetch messages belonging to a specific thread.
The above code snippet returns the messages that belong to the thread with parent id 100.

Hide threaded messages in user/group conversations

Use hideReplies(true) to exclude threaded messages from the main conversation. Default is false.

Hide deleted messages in user/group conversations

Use hideDeletedMessages(true) to exclude deleted messages. Default is false.

Hide quoted messages in user/group conversations

Use hideQuotedMessages(true) to exclude quoted messages. Default is false.

Messages by tags

Use setTags() with a list of tag names to fetch only messages with those tags.

Messages with tags

Use withTags(true) to include tag information in the response. Default is false. When withTags(true) is set, each message’s tags field will be populated. Access tags using getTags().
Use hasLinks(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

Use hasAttachments(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

Use hasReactions(true) to fetch only messages that have 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

Use hasMentions(true) to fetch only messages that contain 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

Use setMentionedUIDs() with a list of UIDs to fetch only messages that mention those 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

Use setAttachmentTypes() with a list of AttachmentType enum values to fetch only 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 with message listeners

Message Structure

Understand message categories and types

Threaded Messages

Implement threaded conversations with parent messages

Retrieve Conversations

Fetch conversation list with unread counts