Skip to main content
Quick Reference for AI Agents & Developers
// Fetch messages for a user conversation
let request = new CometChat.MessagesRequestBuilder().setUID("UID").setLimit(50).build();

// Fetch messages for a group conversation
let request = new CometChat.MessagesRequestBuilder().setGUID("GUID").setLimit(50).build();

// Fetch only unread messages
let request = new CometChat.MessagesRequestBuilder().setUID("UID").setUnread(true).setLimit(30).build();

// Fetch only media messages
let request = new CometChat.MessagesRequestBuilder().setUID("UID").setCategories(["message"]).setTypes(["image", "video", "audio", "file"]).setLimit(30).build();

// Fetch messages, then paginate
let messages = await request.fetchPrevious();
The MessagesRequest class as you must be familiar with helps you to fetch messages based on the various parameters provided to it. This document will help you understand better the various options that are available using the MessagesRequest class.
Available via: SDK | REST API | UI Kits
The MessagesRequest class is designed using the Builder design pattern. In order to obtain an object of the MessagesRequest class, you will have to make use of the MessagesRequestBuilder class in the MessagesRequest class. The MessagesRequestBuilder class allows you to set various parameters to the MessagesRequest class based on which the messages are fetched. Steps to generate an object of the MessagesRequest class:
  1. Create an object of the MessagesRequestBuilder class.
  2. Set all the parameters you wish to set.
  3. Call the build() method of the MessagesRequestBuilder class to get an object of the MessagesRequest class.
Once you have an object of the MessagesRequest class, you can call either the fetchNext() method or the fetchPrevious() method using the object.
  1. fetchNext() - Calling this method will return the messages after the specified parameters.
  2. fetchPrevious() - Calling this method will give you messages before the specified parameters.
Since messages are obtained in a paginated manner, a maximum of 100 messages can be pulled in a single iteration. Calling the fetchPrevious()/fetchNext() method on the same MessagesRequest object will get you the next set of messages. Now that you are clear how to use the MessagesRequest class, below are the various options available:

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 setLimit() method. This method takes an integer value as the input 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.
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setLimit(50)
  .build();
On SuccessfetchPrevious() returns:
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771397762,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771397739,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-de89d7ce-f090-4e2e-ad89-bebae957b3ff-1771397690356",
      "text": "Nice"
    },
    "text": "Nice",
    "id": "25234",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771397739,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771397762,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771398092,
    "deliveredAt": 1771398092,
    "readAt": 1771404705,
    "updatedAt": 1771404705,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]

Messages for a user conversation

In other words, how do I fetch messages between me and any user This can be achieved using the setUID() method. This method takes the UID of the user with whom the conversation is to be fetched. When a valid UID is passed, the SDK will return all the messages that are a part of the conversation between the logged-in user and the UID that has been specified.
let UID = "UID";
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(50)
  .build();
On SuccessfetchPrevious() returns:
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771397762,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771397739,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-de89d7ce-f090-4e2e-ad89-bebae957b3ff-1771397690356",
      "text": "Nice"
    },
    "text": "Nice",
    "id": "25234",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771397739,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771397762,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771398092,
    "deliveredAt": 1771398092,
    "readAt": 1771404705,
    "updatedAt": 1771404705,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]

Messages for a group conversation

In other words, how do I fetch messages for any group conversation You can achieve this using the setGUID() method. This method takes the GUID of a group for which the conversations are to be fetched. Passing a valid GUID to this method will return all the messages that are a part of the group conversation. Please note that the logged-in user must be a member of the group to fetch the messages for that group.
let GUID = "GUID";
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setGUID(GUID)
  .setLimit(50)
  .build();
On SuccessfetchPrevious() returns:
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "group_1748415903905",
    "type": "text",
    "receiverType": "group",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "conversationId": "group_group_1748415903905",
            "createdAt": 1748415957,
            "guid": "group_1748415903905",
            "hasJoined": true,
            "joinedAt": 1749203133,
            "membersCount": 12,
            "name": "3 People Group",
            "onlineMembersCount": 2,
            "owner": "123456",
            "scope": "admin",
            "type": "public",
            "updatedAt": 1771245340
          },
          "entityType": "group"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771397739,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-de89d7ce-f090-4e2e-ad89-bebae957b3ff-1771397690356",
      "text": "Nice"
    },
    "text": "Nice",
    "id": "25237",
    "conversationId": "group_group_1748415903905",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771397739,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasJoined": true,
      "membersCount": 12,
      "isBanned": false,
      "guid": "group_1748415903905",
      "name": "3 People Group",
      "type": "public",
      "conversationId": "group_group_1748415903905",
      "createdAt": 1748415957,
      "joinedAt": 1749203133,
      "onlineMembersCount": 2,
      "owner": "123456",
      "scope": "admin",
      "updatedAt": 1771245340
    },
    "sentAt": 1771400683,
    "updatedAt": 1771400683,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]
If none of the above two methods setUID() and setGUID() is used, all the messages for the logged-in user will be fetched. This means that messages from all the one-on-one and group conversations which the logged-in user is a part of will be returned.> All the parameters discussed below can be used along with the setUID() or setGUID() or without any of the two to fetch all the messages that the logged-in user is a part of.

Messages before/after a message

In other words, how do I fetch messages before or after a particular message This can be achieved using the setMessageId() method. This method takes the message-id as input and provides messages only after/before the message-id based on if the fetchNext() or fetchPrevious() method is triggered.
let UID = "UID";
let messageId = 1;
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setMessageId(messageId)
  .setLimit(limit)
  .build();
On SuccessfetchPrevious() returns:
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771397762,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771397739,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-de89d7ce-f090-4e2e-ad89-bebae957b3ff-1771397690356",
      "text": "UnreadHey"
    },
    "text": "UnreadHey",
    "id": "25233",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771397739,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771397762,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771398088,
    "deliveredAt": 1771398088,
    "updatedAt": 1771398088,
    "readAt": 1771404705,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]
This method can be used along with setUID() or setGUID() methods 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 You can easily achieve this using the setTimestamp() method. This method takes the Unix timestamp as input and provides messages only after/before the timestamp based on if fetchNext() or fetchPrevious() method is triggered.
let UID = "UID";
let timestamp = 1602221371;
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setTimestamp(timestamp)
  .setLimit(limit)
  .build();
On SuccessfetchPrevious() returns:
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "test-custom",
    "receiverType": "user",
    "category": "custom",
    "customData": {
      "greeting": "Hello from custom message!",
      "timestamp": 1771324022864
    },
    "data": {
      "customData": {
        "greeting": "Hello from custom message!",
        "timestamp": 1771324022864
      },
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771323089,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771323567,
            "name": "Nancy Grace",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-5cebfc4b-80f7-44df-8a0a-5a760ffe5239-1771321973734",
      "text": "Sent a custom message"
    },
    "id": "25191",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771323567,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771323089,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771324025,
    "deliveredAt": 1771328175,
    "readAt": 1771328175,
    "updatedAt": 1771328175,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]
This method can be used along with setUID() or setGUID() methods 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 This can easily be achieved using setting the unread flag to true. For this, you need to use the setUnread() method. This method takes a boolean value as input. If the value is set to true, the SDK will return just the unread messages.
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setUnread(true)
  .setLimit(limit)
  .build();
On SuccessfetchPrevious() returns:
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771413280,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771413285,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-3f872f7b-f581-40da-b6d3-96ebb6de9cdf-1771411970682",
      "text": "You there?"
    },
    "text": "You there?",
    "id": "25241",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771413285,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771413280,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771413707,
    "deliveredAt": 1771413707,
    "updatedAt": 1771413707,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]
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

In other words, how do I fetch messages excluding the messages from the users I have blocked This can be easily achieved using the hideMessagesFromBlockedUsers() method. This method accepts a boolean value which determines if the messages from users blocked by the logged-in user need to be a part if the fetched messages. If the value is set to true, the messages will be hidden and won’t be a part of the messages fetched. The default value is false i.e if this method is not used, the messages from blocked users will be included in the fetched messages.
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .hideMessagesFromBlockedUsers(true)
  .setLimit(limit)
  .build();
On SuccessfetchPrevious() returns (messages from blocked users are excluded):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "group_1748415903905",
    "type": "group-call",
    "receiverType": "group",
    "category": "custom",
    "customData": {
      "callType": "audio",
      "isCaller": true,
      "sessionId": "v1.in.2748663902141719.1771413265424256434f95643946315f45d0fd9058f55b625b"
    },
    "data": {
      "customData": {
        "callType": "audio",
        "isCaller": true,
        "sessionId": "v1.in.2748663902141719.1771413265424256434f95643946315f45d0fd9058f55b625b"
      },
      "entities": {
        "receiver": {
          "entity": {
            "conversationId": "group_group_1748415903905",
            "createdAt": 1748415957,
            "guid": "group_1748415903905",
            "hasJoined": true,
            "joinedAt": 1748437105,
            "membersCount": 12,
            "name": "3 People Group",
            "onlineMembersCount": 1,
            "owner": "123456",
            "scope": "admin",
            "type": "public",
            "updatedAt": 1771245340
          },
          "entityType": "group"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "lastActiveAt": 1771412068,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "moderation": {
        "status": "approved"
      },
      "resource": "REACT_NATIVE-4_0_14-8de3c0b7-fa09-4b9e-b321-9a085d81b1d5-1771411979132",
      "text": "Group video call started. Tap to join!"
    },
    "id": "25239",
    "conversationId": "group_group_1748415903905",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771412068,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasJoined": true,
      "membersCount": 12,
      "isBanned": false,
      "guid": "group_1748415903905",
      "name": "3 People Group",
      "type": "public",
      "conversationId": "group_group_1748415903905",
      "createdAt": 1748415957,
      "joinedAt": 1748437105,
      "onlineMembersCount": 1,
      "owner": "123456",
      "scope": "admin",
      "updatedAt": 1771245340
    },
    "sentAt": 1771413265,
    "updatedAt": 1771413265,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]
This method can be used to hide the messages by users blocked by logged in user in groups that both the members are a part of.

Updated and received messages

In other words, how do I fetch messages that have been received or updated after a particular date or time This method accepts a Unix timestamp value and will return all the messages that have been updated and the ones that have been sent/received after the specified time. The messages updated could mean the messages that have been marked as read/delivered or if the messages are edited or deleted.
let UID = "UID";
let limit = 30;
let timestamp = 1602221371;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setUpdatedAfter(timestamp)
  .setLimit(limit)
  .build();
On SuccessfetchNext() returns:
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771397762,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771397739,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-de89d7ce-f090-4e2e-ad89-bebae957b3ff-1771397690356",
      "text": "Nice"
    },
    "text": "Nice",
    "id": "25234",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771397739,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771397762,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771398092,
    "deliveredAt": 1771398092,
    "readAt": 1771404705,
    "updatedAt": 1771404705,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]
This can be useful in finding the messages that have been received or updated after a certain time. Can prove very useful if you are saving the messages locally and would like to know the messages that have been updated or received after the last message available in your local databases.

Updated messages only

In other words, how do I fetch messages that have been updated after a particular date or time This can be achieved easily by setting the updatesOnly parameter to true. To do so, you can use the updatesOnly() method. This method takes a boolean input and can be used with the setUpdatedAfter() method to get just the updated messages and not the messages sent/received after the specified time. This method cannot be used independently and always needs to be used with the setUpdatedAfter() method.
let UID = "UID";
let limit = 30;
let timestamp = 1602221371;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setUpdatedAfter(timestamp)
  .updatesOnly(true)
  .setLimit(limit)
  .build();
On SuccessfetchNext() returns (only updated messages, e.g. read receipt changes):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-3",
    "type": "image",
    "receiverType": "user",
    "category": "message",
    "data": {
      "attachments": [
        {
          "extension": "png",
          "mimeType": "image/png",
          "name": "photo.png",
          "size": 2295572,
          "url": "https://data-in.cometchat.io/2748663902141719/media/1771323061_1750099251_c35f9734fc20947b7456bbea68126f99.png"
        }
      ],
      "category": "message",
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771322968,
            "name": "Nancy Grace",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "lastActiveAt": 1771323060,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        }
      },
      "moderation": {
        "status": "approved"
      },
      "resource": "REACT_NATIVE-4_0_14-542c56fc-a1a6-4df4-a5e4-549f3cf17550-1771321970718",
      "type": "image",
      "url": "https://data-in.cometchat.io/2748663902141719/media/1771323061_1750099251_c35f9734fc20947b7456bbea68126f99.png"
    },
    "id": "25189",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771323060,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771322968,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "sentAt": 1771323061,
    "deliveredAt": 1771323062,
    "readAt": 1771323227,
    "updatedAt": 1771323227
  },
  // ... more messages up to the specified limit
]

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. For this, you will have to use the setCategories() method. This method accepts a list of categories. This tells the SDK to fetch messages only belonging to these categories.
let UID = "UID";
let limit = 30;
let categories = ["message", "custom"];
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setCategories(categories)
  .setLimit(limit)
  .build();
On SuccessfetchPrevious() returns (includes both custom and message categories):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "extension_poll",
    "receiverType": "user",
    "category": "custom",
    "customData": {
      "id": "fde49a5e-baa8-4e04-95e9-c2c09557caa0",
      "options": {
        "1": "Yes",
        "2": "No"
      },
      "question": "Custom"
    },
    "data": {
      "customData": {
        "id": "fde49a5e-baa8-4e04-95e9-c2c09557caa0",
        "options": {
          "1": "Yes",
          "2": "No"
        },
        "question": "Custom"
      },
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "createdAt": 1746375164,
            "lastActiveAt": 1771474191,
            "name": "George Alan",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "createdAt": 1746375164,
            "lastActiveAt": 1771474104,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            },
            "polls": {
              "id": "fde49a5e-baa8-4e04-95e9-c2c09557caa0",
              "options": {
                "1": "Yes",
                "2": "No"
              },
              "question": "Custom",
              "results": {
                "options": {
                  "1": {
                    "count": 0,
                    "text": "Yes"
                  },
                  "2": {
                    "count": 0,
                    "text": "No"
                  }
                },
                "total": 0
              }
            }
          }
        },
        "incrementUnreadCount": true,
        "pushNotification": "Poll: Custom"
      },
      "text": "Custom",
      "updateConversation": true
    },
    "id": "25251",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771474104,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771474191,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "sentAt": 1771474256,
    "deliveredAt": 1771474256,
    "readAt": 1771474256,
    "updatedAt": 1771474256,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          },
          "polls": {
            "id": "fde49a5e-baa8-4e04-95e9-c2c09557caa0",
            "options": {
              "1": "Yes",
              "2": "No"
            },
            "question": "Custom",
            "results": {
              "options": {
                "1": {
                  "count": 0,
                  "text": "Yes"
                },
                "2": {
                  "count": 0,
                  "text": "No"
                }
              },
              "total": 0
            }
          }
        }
      },
      "incrementUnreadCount": true,
      "pushNotification": "Poll: Custom"
    }
  },
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771474191,
            "name": "George Alan",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771474104,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "text": "Hello Message"
    },
    "text": "Hello Message",
    "id": "25252",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771474104,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771474191,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "sentAt": 1771474273,
    "deliveredAt": 1771474274,
    "readAt": 1771474274,
    "updatedAt": 1771474274,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]
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 setGUID() and setUID() 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 before trying this, you refer to the Message structure and hierarchy guide to get familiar with the various types of messages. This can be easily achieved using the setTypes() method. This method accepts a list of types. This tells the SDK to fetch messages only belonging to these types.
let UID = "UID";
let limit = 30;
let categories = ["message"];
let types = ["image", "video", "audio", "file"];
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setCategories(categories)
  .setTypes(types)
  .setLimit(limit)
  .build();
On SuccessfetchPrevious() returns (only image, video, audio, file types):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "image",
    "receiverType": "user",
    "category": "message",
    "data": {
      "attachments": [
        {
          "extension": "jpg",
          "mimeType": "image/jpeg",
          "name": "photo.jpg",
          "size": 142099,
          "url": "https://data-in.cometchat.io/2748663902141719/media/1771474540_739339167_565af45463f0170fda1720c8138a7761.jpg"
        }
      ],
      "category": "message",
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771474191,
            "name": "George Alan",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771474535,
            "name": "Nancy Grace",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "type": "image",
      "url": "https://data-in.cometchat.io/2748663902141719/media/1771474540_739339167_565af45463f0170fda1720c8138a7761.jpg"
    },
    "id": "25253",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771474535,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771474191,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "sentAt": 1771474540,
    "deliveredAt": 1771474540,
    "readAt": 1771474540,
    "updatedAt": 1771474540
  },
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "audio",
    "receiverType": "user",
    "category": "message",
    "data": {
      "attachments": [
        {
          "extension": "ogg",
          "mimeType": "application/ogg",
          "name": "audio.ogg",
          "size": 12059,
          "url": "https://data-in.cometchat.io/2748663902141719/media/1771474570_2022717407_2842560f3be961ab9264c48b5721a60d.ogg"
        }
      ],
      "category": "message",
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771474191,
            "name": "George Alan",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771474559,
            "name": "Nancy Grace",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "type": "audio",
      "url": "https://data-in.cometchat.io/2748663902141719/media/1771474570_2022717407_2842560f3be961ab9264c48b5721a60d.ogg"
    },
    "id": "25254",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771474559,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771474191,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "sentAt": 1771474570,
    "deliveredAt": 1771474570,
    "readAt": 1771474570,
    "updatedAt": 1771474570
  },
  // ... more messages up to the specified limit
]
Using the above code snippet, you can fetch all the media messages. This along with setUID() or setGUID() 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 conversation This can be done using the setParentMessageId() method. This method needs to be used when you have implemented threaded conversations in your app. This method will return the messages only belonging to the thread with the specified parent Id.
let UID = "UID";
let messageId = 1; // Use msg.getId() on a message where msg.getReplyCount() > 0
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .setParentMessageId(messageId)
  .build();
On SuccessfetchPrevious() returns (messages belonging to the specified thread):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771475047,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771475038,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "text": "Thread Message"
    },
    "text": "Thread Message",
    "id": "25257",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771475038,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771475047,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771476403,
    "deliveredAt": 1771476404,
    "readAt": 1771476404,
    "updatedAt": 1771476404,
    "parentMessageId": "25256",
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]
The above code snippet returns the messages that belong to the thread with parent id 100.

Hide threaded messages in user/group conversations

In other words, how do I exclude threaded messages from the normal user/group conversations In order to do this, you can use the hideReplies() method. This method is also related to threaded conversations. This method takes boolean as input. This boolean when set to true will make sure that the messages that belong to threads are not fetched. If set to false, which is also the default value, the messages belong to the threads will also be fetched along with other messages.
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .hideReplies(true)
  .build();
On SuccessfetchPrevious() returns (threaded replies are excluded, parent messages with threads still appear):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "audio",
    "receiverType": "user",
    "category": "message",
    "data": {
      "attachments": [
        {
          "extension": "ogg",
          "mimeType": "application/ogg",
          "name": "audio.ogg",
          "size": 12059,
          "url": "https://data-in.cometchat.io/2748663902141719/media/1771474570_2022717407_2842560f3be961ab9264c48b5721a60d.ogg"
        }
      ],
      "category": "message",
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771474191,
            "name": "George Alan",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771474559,
            "name": "Nancy Grace",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "type": "audio",
      "url": "https://data-in.cometchat.io/2748663902141719/media/1771474570_2022717407_2842560f3be961ab9264c48b5721a60d.ogg"
    },
    "id": "25254",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771474559,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771474191,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "sentAt": 1771474570,
    "deliveredAt": 1771474570,
    "readAt": 1771474570,
    "updatedAt": 1771474570
  },
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771475047,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771475038,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "text": "New Message for Thread"
    },
    "text": "New Message for Thread",
    "id": "25256",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771475038,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771475047,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771476391,
    "deliveredAt": 1771476392,
    "readAt": 1771476392,
    "updatedAt": 1771476392,
    "replyCount": 1,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]

Hide deleted messages in user/group conversations

In other words, how do I exclude deleted messages from a user/group conversation In order to do this, you can use the hideDeletedMessages() method. This method takes boolean as input. This boolean when set to true will make sure that the deleted messages are not fetched. If set to false, which is also the default value, the deleted messages will also be fetched along with other messages.
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .hideDeletedMessages(true)
  .build();
On SuccessfetchPrevious() returns (deleted messages are excluded):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771475047,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771475038,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "text": "New Message for Thread"
    },
    "text": "New Message for Thread",
    "id": "25256",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771475038,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771475047,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771476391,
    "deliveredAt": 1771476392,
    "readAt": 1771476392,
    "updatedAt": 1771476392,
    "replyCount": 1,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771475047,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771475038,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "text": "Thread Message"
    },
    "text": "Thread Message",
    "id": "25257",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771475038,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771475047,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771476403,
    "deliveredAt": 1771476404,
    "readAt": 1771476404,
    "updatedAt": 1771476404,
    "parentMessageId": "25256",
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]

Messages by tags

In other words, how do I fetch messages by tags In order to do this, you can use the setTags() method. This method accepts a list of tags. This tells the SDK to fetch messages only belonging to these tags.
let UID = "UID";
let limit = 30;
let tags = ["starredMessage"];
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .setTags(tags)
  .build();
On SuccessfetchPrevious() returns (only messages matching the specified tags):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771477541,
            "name": "George Alan",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771478591,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "text": "Tagged message for docs"
    },
    "text": "Tagged message for docs",
    "id": "25259",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771478591,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771477541,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "sentAt": 1771478898,
    "deliveredAt": 1771478900,
    "readAt": 1771478900,
    "updatedAt": 1771478900,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-3",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771478591,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "lastActiveAt": 1771477541,
            "name": "George Alan",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "moderation": {
        "status": "approved"
      },
      "resource": "REACT_NATIVE-4_0_14-99626bfc-ffc1-4059-be3a-b7c77ee4cbcd-1771474097650",
      "text": "Tagged message for docs"
    },
    "text": "Tagged message for docs",
    "id": "25260",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771477541,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771478591,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771478922,
    "updatedAt": 1771478922,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]

Messages with tags

In other words, how do I fetch messages with the tags information In order to do this, you can use the withTags() method. This method accepts boolean as input. When set to true , the SDK will fetch messages along with the tags. When set to false , the SDK will not fetch tags associated with messages. The default value for this parameter is false .
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .withTags(true)
  .build();
On SuccessfetchPrevious() returns (messages include the tags field):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-3",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771480251,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "lastActiveAt": 1771480243,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "moderation": {
        "status": "approved"
      },
      "resource": "REACT_NATIVE-4_0_14-99626bfc-ffc1-4059-be3a-b7c77ee4cbcd-1771474097650",
      "text": "Tagged message for docs"
    },
    "text": "Tagged message for docs",
    "id": "25265",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771480243,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771480251,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771481257,
    "updatedAt": 1771481257,
    "tags": ["starredMessage"],
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-3",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771480251,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "lastActiveAt": 1771480243,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "moderation": {
        "status": "pending"
      },
      "resource": "REACT_NATIVE-4_0_14-99626bfc-ffc1-4059-be3a-b7c77ee4cbcd-1771474097650",
      "text": "Tagged message for docs"
    },
    "text": "Tagged message for docs",
    "id": "25266",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771480243,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771480251,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771481270,
    "updatedAt": 1771481270,
    "tags": ["starredMessage"],
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]
In other words, as a logged-in user, how do I fetch messages that contain links? In order to do this, you can use the hasLinks() method. This method accepts boolean as input. When set to true , the SDK will fetch messages which have links in the text. The default value for this parameter 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)
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .hasLinks(true)
  .build();
On SuccessfetchPrevious() returns (only messages containing links):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771480243,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771480251,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": [
                {
                  "description": "Build real time chat, voice and video calling experience with CometChat's flexible SDKs, APIs & UI Kits. Sign up now!\n",
                  "favicon": "https://cometchat.com/_static/favicon.png",
                  "image": "https://a.storyblok.com/f/231922/1200x630/d639d0748b/open-graph-image.png/m/1200x630/",
                  "title": "In-app Chat SDK & API For Messaging And Calling - CometChat",
                  "url": "https://cometchat.com"
                }
              ]
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "text": "Please checkout our website https://cometchat.com"
    },
    "text": "Please checkout our website https://cometchat.com",
    "id": "25269",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771480251,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771480243,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771481824,
    "deliveredAt": 1771481825,
    "readAt": 1771481825,
    "updatedAt": 1771481825,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": [
              {
                "description": "Build real time chat, voice and video calling experience with CometChat's flexible SDKs, APIs & UI Kits. Sign up now!\n",
                "favicon": "https://cometchat.com/_static/favicon.png",
                "image": "https://a.storyblok.com/f/231922/1200x630/d639d0748b/open-graph-image.png/m/1200x630/",
                "title": "In-app Chat SDK & API For Messaging And Calling - CometChat",
                "url": "https://cometchat.com"
              }
            ]
          }
        }
      }
    }
  },
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771482544,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771482552,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": [
                {
                  "description": "",
                  "favicon": "http://www.google.com/favicon.ico",
                  "image": "",
                  "title": "Google",
                  "url": "http://www.google.com"
                }
              ]
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "text": "Www.google.com"
    },
    "text": "Www.google.com",
    "id": "25270",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771482552,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771482544,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771482630,
    "deliveredAt": 1771482631,
    "readAt": 1771482631,
    "updatedAt": 1771482631,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": [
              {
                "description": "",
                "favicon": "http://www.google.com/favicon.ico",
                "image": "",
                "title": "Google",
                "url": "http://www.google.com"
              }
            ]
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]

Messages with attachments

In other words, as a logged-in user, how do I fetch messages that contain attachments? In order to do this, you can use the hasAttachments() method. This method accepts boolean as input. When set to true , the SDK will fetch messages which have attachments (image, audio, video or file). The default value for this parameter 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)
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .hasAttachments(true)
  .build();
On SuccessfetchPrevious() returns (only messages with attachments):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "image",
    "receiverType": "user",
    "category": "message",
    "data": {
      "attachments": [
        {
          "extension": "jpg",
          "mimeType": "image/jpeg",
          "name": "IMG_20260217_150412.jpg",
          "size": 142099,
          "url": "https://data-in.cometchat.io/2748663902141719/media/1771474540_739339167_565af45463f0170fda1720c8138a7761.jpg"
        }
      ],
      "category": "message",
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771474191,
            "name": "George Alan",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771474535,
            "name": "Nancy Grace",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "type": "image",
      "url": "https://data-in.cometchat.io/2748663902141719/media/1771474540_739339167_565af45463f0170fda1720c8138a7761.jpg"
    },
    "id": "25253",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771474535,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771474191,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "sentAt": 1771474540,
    "deliveredAt": 1771474540,
    "readAt": 1771474540,
    "updatedAt": 1771474540
  },
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "audio",
    "receiverType": "user",
    "category": "message",
    "data": {
      "attachments": [
        {
          "extension": "ogg",
          "mimeType": "application/ogg",
          "name": "Music%20Box.ogg",
          "size": 12059,
          "url": "https://data-in.cometchat.io/2748663902141719/media/1771474570_2022717407_2842560f3be961ab9264c48b5721a60d.ogg"
        }
      ],
      "category": "message",
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771474191,
            "name": "George Alan",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771474559,
            "name": "Nancy Grace",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "type": "audio",
      "url": "https://data-in.cometchat.io/2748663902141719/media/1771474570_2022717407_2842560f3be961ab9264c48b5721a60d.ogg"
    },
    "id": "25254",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771474559,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771474191,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "sentAt": 1771474570,
    "deliveredAt": 1771474570,
    "readAt": 1771474570,
    "updatedAt": 1771474570
  },
  // ... more messages up to the specified limit
]

Messages with reactions

In other words, as a logged-in user, how do I fetch messages that contain reactions? In order to do this, you can use the hasReactions() method. This method accepts boolean as input. When set to true , the SDK will fetch messages which have reactions. The default value for this parameter 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)
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .hasReactions(true)
  .build();
On SuccessfetchPrevious() returns (only messages that have reactions):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771494233,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771495034,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-0790756b-527d-443d-b3e6-6ce85a085e7f-1771494137056",
      "text": "Message with reactions",
      "reactions": [
        {
          "reaction": "❤️",
          "count": 1
        },
        {
          "reaction": "😮",
          "count": 1,
          "reactedByMe": true
        }
      ]
    },
    "text": "Message with reactions",
    "id": "25275",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771495034,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771494233,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771495045,
    "deliveredAt": 1771495045,
    "readAt": 1771495045,
    "updatedAt": 1771495045,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]

Messages with mentions

In other words, as a logged-in user, how do I fetch messages that contain mentions? In order to do this, you can use the hasMentions() method. This method accepts boolean as input. When set to true , the SDK will fetch messages which have mentions. The default value for this parameter 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)
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .hasMentions(true)
  .build();
On SuccessfetchPrevious() returns (only messages that contain mentions):
[
  {
    "reactions": [],
    "mentionedUsers": [
      {
        "hasBlockedMe": false,
        "blockedByMe": false,
        "deactivatedAt": 0,
        "uid": "cometchat-uid-2",
        "name": "George Alan",
        "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
        "lastActiveAt": 1771494233,
        "role": "default",
        "status": "online"
      }
    ],
    "mentionedMe": true,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771482544,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771482552,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "text": "<@uid:cometchat-uid-2> Hello",
      "mentions": {
        "cometchat-uid-2": {
          "uid": "cometchat-uid-2",
          "name": "George Alan",
          "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
          "status": "online",
          "role": "default",
          "lastActiveAt": 1771494233
        }
      }
    },
    "text": "<@uid:cometchat-uid-2> Hello",
    "id": "25271",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771482552,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771482544,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771482742,
    "deliveredAt": 1771482743,
    "readAt": 1771482743,
    "updatedAt": 1771482743,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  {
    "reactions": [],
    "mentionedUsers": [
      {
        "hasBlockedMe": false,
        "blockedByMe": false,
        "deactivatedAt": 0,
        "uid": "cometchat-uid-2",
        "name": "George Alan",
        "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
        "lastActiveAt": 1771494233,
        "role": "default",
        "status": "online"
      }
    ],
    "mentionedMe": true,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771494233,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771495034,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-0790756b-527d-443d-b3e6-6ce85a085e7f-1771494137056",
      "text": "Message for mentioned users, Hello <@uid:cometchat-uid-2>",
      "mentions": {
        "cometchat-uid-2": {
          "uid": "cometchat-uid-2",
          "name": "George Alan",
          "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
          "status": "online",
          "role": "default",
          "lastActiveAt": 1771494233
        }
      }
    },
    "text": "Message for mentioned users, Hello <@uid:cometchat-uid-2>",
    "id": "25276",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771495034,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771494233,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771495242,
    "deliveredAt": 1771495244,
    "readAt": 1771495244,
    "updatedAt": 1771495244,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]

Messages with particular user mentions

In other words, as a logged-in user, how do I fetch messages that mention specific users? In order to do this, you can use the setMentionedUIDs() method. This method accepts an array of UIDs as input. When set, the SDK will fetch messages which have the mentions of the UIDs passed.
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)
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .setMentionedUIDs(["UID"])
  .build();
On SuccessfetchPrevious() returns (only messages mentioning the specified UIDs):
[
  {
    "reactions": [],
    "mentionedUsers": [
      {
        "hasBlockedMe": false,
        "blockedByMe": false,
        "deactivatedAt": 0,
        "uid": "cometchat-uid-2",
        "name": "George Alan",
        "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
        "lastActiveAt": 1771494233,
        "role": "default",
        "status": "online"
      }
    ],
    "mentionedMe": true,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771482544,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771482552,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "text": "<@uid:cometchat-uid-2> Hello",
      "mentions": {
        "cometchat-uid-2": {
          "uid": "cometchat-uid-2",
          "name": "George Alan",
          "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
          "status": "online",
          "role": "default",
          "lastActiveAt": 1771494233
        }
      }
    },
    "text": "<@uid:cometchat-uid-2> Hello",
    "id": "25271",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771482552,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771482544,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771482742,
    "deliveredAt": 1771482743,
    "readAt": 1771482743,
    "updatedAt": 1771482743,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  {
    "reactions": [],
    "mentionedUsers": [
      {
        "hasBlockedMe": false,
        "blockedByMe": false,
        "deactivatedAt": 0,
        "uid": "cometchat-uid-2",
        "name": "George Alan",
        "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
        "lastActiveAt": 1771494233,
        "role": "default",
        "status": "online"
      }
    ],
    "mentionedMe": true,
    "receiverId": "cometchat-uid-2",
    "type": "text",
    "receiverType": "user",
    "category": "message",
    "data": {
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771494233,
            "name": "George Alan",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771495034,
            "name": "Nancy Grace",
            "role": "default",
            "status": "online",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "metadata": {
        "@injected": {
          "extensions": {
            "link-preview": {
              "links": []
            }
          }
        }
      },
      "resource": "REACT_NATIVE-4_0_14-0790756b-527d-443d-b3e6-6ce85a085e7f-1771494137056",
      "text": "Message for mentioned users, Hello <@uid:cometchat-uid-2>",
      "mentions": {
        "cometchat-uid-2": {
          "uid": "cometchat-uid-2",
          "name": "George Alan",
          "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
          "status": "online",
          "role": "default",
          "lastActiveAt": 1771494233
        }
      }
    },
    "text": "Message for mentioned users, Hello <@uid:cometchat-uid-2>",
    "id": "25276",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771495034,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771494233,
      "role": "default",
      "status": "online",
      "tags": []
    },
    "sentAt": 1771495242,
    "deliveredAt": 1771495244,
    "readAt": 1771495244,
    "updatedAt": 1771495244,
    "metadata": {
      "@injected": {
        "extensions": {
          "link-preview": {
            "links": []
          }
        }
      }
    }
  },
  // ... more messages up to the specified limit
]

Messages with specific attachment types

In other words, as a logged-in user, how do I fetch messages that contain specific types of attachments? In order to do this, you can use the setAttachmentTypes() method. This method accepts an array of CometChat.AttachmentType ENUM values as input. When provided, the SDK will fetch only those messages that include attachments of the specified types (such as image, audio, video, or file).
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)
let UID = "UID";
let limit = 30;
let messagesRequest = new CometChat.MessagesRequestBuilder()
  .setUID(UID)
  .setLimit(limit)
  .setAttachmentTypes([CometChat.AttachmentType.IMAGE, CometChat.AttachmentType.VIDEO])
  .build();
On SuccessfetchPrevious() returns (only messages with the specified attachment types):
[
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "image",
    "receiverType": "user",
    "category": "message",
    "data": {
      "attachments": [
        {
          "extension": "jpg",
          "mimeType": "image/jpeg",
          "name": "IMG_20260217_150412.jpg",
          "size": 142099,
          "url": "https://data-in.cometchat.io/2748663902141719/media/1771386517_1811543964_565af45463f0170fda1720c8138a7761.jpg"
        }
      ],
      "category": "message",
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771386436,
            "name": "George Alan",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771386507,
            "name": "Nancy Grace",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "resource": "REACT_NATIVE-4_0_14-e00a3397-8084-4596-9425-35f7e61a1111-1771332420737",
      "type": "image",
      "url": "https://data-in.cometchat.io/2748663902141719/media/1771386517_1811543964_565af45463f0170fda1720c8138a7761.jpg"
    },
    "id": "25196",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771386507,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771386436,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "sentAt": 1771386517,
    "deliveredAt": 1771386517,
    "readAt": 1771483750,
    "updatedAt": 1771483750
  },
  {
    "reactions": [],
    "mentionedUsers": [],
    "mentionedMe": false,
    "receiverId": "cometchat-uid-2",
    "type": "image",
    "receiverType": "user",
    "category": "message",
    "data": {
      "attachments": [
        {
          "extension": "jpg",
          "mimeType": "image/jpeg",
          "name": "IMG_20260217_150412.jpg",
          "size": 142099,
          "url": "https://data-in.cometchat.io/2748663902141719/media/1771474540_739339167_565af45463f0170fda1720c8138a7761.jpg"
        }
      ],
      "category": "message",
      "entities": {
        "receiver": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
            "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
            "lastActiveAt": 1771474191,
            "name": "George Alan",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-2"
          },
          "entityType": "user"
        },
        "sender": {
          "entity": {
            "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
            "lastActiveAt": 1771474535,
            "name": "Nancy Grace",
            "role": "default",
            "status": "offline",
            "tags": [],
            "uid": "cometchat-uid-3"
          },
          "entityType": "user"
        }
      },
      "resource": "REACT_NATIVE-4_0_14-d4a0f137-38d3-46d2-85e7-01084854e826-1771474101564",
      "type": "image",
      "url": "https://data-in.cometchat.io/2748663902141719/media/1771474540_739339167_565af45463f0170fda1720c8138a7761.jpg"
    },
    "id": "25253",
    "conversationId": "cometchat-uid-2_user_cometchat-uid-3",
    "sender": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-3",
      "name": "Nancy Grace",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
      "lastActiveAt": 1771474535,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "receiver": {
      "hasBlockedMe": false,
      "blockedByMe": false,
      "deactivatedAt": 0,
      "uid": "cometchat-uid-2",
      "name": "George Alan",
      "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-2.webp",
      "lastActiveAt": 1771474191,
      "role": "default",
      "status": "offline",
      "tags": []
    },
    "sentAt": 1771474540,
    "deliveredAt": 1771474540,
    "readAt": 1771474540,
    "updatedAt": 1771474540
  },
  // ... more messages up to the specified limit
]

Best Practices & Troubleshooting

Always call fetchNext() or fetchPrevious() on the same MessagesRequest object to paginate through results. Creating a new MessagesRequest object will reset pagination and start from the beginning.
You can chain multiple builder methods together (e.g., setCategories() + setTypes() + setUID()) to narrow down results. This is more efficient than fetching all messages and filtering client-side.
If you store messages locally, use setUpdatedAfter() with the timestamp of your last synced message to fetch only new or updated messages. Combine with updatesOnly(true) if you only need edits, deletions, and read/delivery status changes.
The maximum limit per fetch is 100. For most UI use cases, a limit of 30–50 provides a good balance between performance and user experience. Smaller limits mean faster responses and less memory usage.
If fetchNext() or fetchPrevious() returns an empty array, verify that: the logged-in user is a member of the group (for group conversations), the UID/GUID is correct, and the applied filters aren’t too restrictive. Try removing filters one at a time to isolate the issue.
Methods like hasLinks(), hasAttachments(), hasReactions(), hasMentions(), setMentionedUIDs(), and setAttachmentTypes() require the Conversation & Advanced Search feature to be enabled. Ensure you are on an Advanced or Custom plan and have enabled the feature from the CometChat Dashboard (Chats → Settings → General Configuration).

Next Steps