Documentation Index
Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
AI Integration Quick Reference
AI Integration Quick Reference
uid, guid, limit, categories, types, tags, unread, parentMessageId, messageId, timestamp, hideReplies, hideDeleted, hideQuotedMessages, searchKeyword, updatedAfter, updatesOnly, hideMessagesFromBlockedUsers, withTags, hasMentions, hasLinks, hasAttachments, hasReactions, mentionedUids, attachmentTypes, withParentMessagesRequest 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:
- Create a
MessagesRequestBuilderobject - Set your desired parameters
- Call
build()to get aMessagesRequestobject - Call
fetchNext()orfetchPrevious()to retrieve messages
| Method | Description |
|---|---|
fetchNext() | Returns messages after the specified parameters |
fetchPrevious() | Returns messages before the specified parameters |
fetchPrevious()/fetchNext() repeatedly on the same object gets subsequent pages.
MessagesRequestBuilder Parameters
| Parameter | Type | Description |
|---|---|---|
uid | String? | User ID to fetch conversation messages for |
guid | String? | Group ID to fetch conversation messages for |
limit | int? | Number of messages per request (max 100, default 30) |
messageId | int? | Fetch messages before/after this message ID |
timestamp | DateTime? | Fetch messages before/after this timestamp |
unread | bool? | Fetch only unread messages |
hideMessagesFromBlockedUsers | bool? | Exclude messages from blocked users (default false) |
searchKeyword | String? | Search keyword to filter messages |
updatedAfter | DateTime? | Fetch messages updated/received after this time |
updatesOnly | bool? | Fetch only updated messages (use with updatedAfter) |
category | String? | Single message category filter |
type | String? | Single message type filter |
parentMessageId | int? | Fetch messages in a specific thread |
hideReplies | bool? | Exclude threaded messages (default false) |
hideDeleted | bool? | Exclude deleted messages (default false) |
categories | List<String>? | Filter by multiple message categories |
types | List<String>? | Filter by multiple message types |
withTags | bool? | Include tag information in response (default false) |
tags | List<String>? | Filter by specific tags |
hasMentions | bool? | Fetch only messages with mentions (default false) |
hasLinks | bool? | Fetch only messages with links (default false) |
hasAttachments | bool? | Fetch only messages with attachments (default false) |
hasReactions | bool? | Fetch only messages with reactions (default false) |
mentionedUids | List<String>? | Fetch messages mentioning specific users |
attachmentTypes | List<String>? | Filter by specific attachment types |
interactionGoalCompletedOnly | bool? | Fetch only messages with completed interaction goals (default false) |
withParent | bool? | Include parent message with replies (default false) |
hideQuotedMessages | bool? | Exclude quoted messages (default false) |
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 thelimit 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.
- Dart
Messages for a user conversation
In other words, how do I fetch messages between me and any user Use theuid property to fetch messages between the logged-in user and a specific user.
- Dart
Messages for a group conversation
In other words, how do I fetch messages for any group conversation Use theguid property to fetch messages from a group. The logged-in user must be a member of the group.
- Dart
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 themessageId property. This provides messages only after/before the message-id based on if fetchNext() or fetchPrevious() is called.
- Dart
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 thetimestamp property. This takes a DateTime value and provides messages only after/before the timestamp based on if fetchNext() or fetchPrevious() is called.
- Dart
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 theunread property set to true to return just the unread messages.
- Dart
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 thehideMessagesFromBlockedUsers property. If set to true, messages from users blocked by the logged-in user will be excluded. Default is false.
- Dart
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 theupdatedAfter 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.
- Dart
Updated messages only
In other words, how do I fetch messages that have been updated after a particular date or time Use theupdatesOnly 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.
- Dart
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 thecategories property with a list of category names to filter by message category.
- Dart
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 thetypes property with a list of type names to filter by message type.
- Dart
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 theparentMessageId property when you have implemented threaded conversations. This will return only messages belonging to the thread with the specified parent ID.
- Dart
Hide threaded messages in user/group conversations
In other words, how do I exclude threaded messages from the normal user/group conversations Use thehideReplies property set to true to exclude messages that belong to threads. Default is false.
- Dart
Hide deleted messages in user/group conversations
In other words, how do I exclude deleted messages a user/group conversations Use thehideDeleted property set to true to exclude deleted messages. Default is false.
- Dart
Hide quoted messages in user/group conversations
In other words, how do I exclude quoted messages from user/group conversations Use thehideQuotedMessages property set to true to exclude quoted messages. Default is false.
- Dart
Messages by tags
In other words, how do I fetch messages belonging to specific tags Use thetags property with a list of tag names to fetch only messages with those tags.
- Dart
Messages with tags
In other words, how do I fetch messages with the tags information Use thewithTags property set to true to include tag information in the response. Default is false.
- Dart
withTags is set to true, each message’s tags field will be populated.
| Additional Field | Type | Description |
|---|---|---|
| tags | List<String> | Tags associated with the message |
Messages with links
In other words, as a logged-in user, how do I fetch messages that contain links? Use thehasLinks 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)- Dart
Messages with attachments
In other words, as a logged-in user, how do I fetch messages that contain attachments? Use thehasAttachments 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)- Dart
Messages with reactions
In other words, as a logged-in user, how do I fetch messages that contain reactions? Use thehasReactions 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)- Dart
Messages with mentions
In other words, as a logged-in user, how do I fetch messages that contain mentions? Use thehasMentions 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)- Dart
Messages with particular user mentions
In other words, as a logged-in user, how do I fetch messages that mention specific users? Use thementionedUids 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)- Dart
Messages with specific attachment types
In other words, as a logged-in user, how do I fetch messages with specific types of attachments? Use theattachmentTypes 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)- Dart
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