AI Integration Quick Reference
AI Integration Quick Reference
User objects.
User Object Fields
| Field | Getter | Return Type | Description |
|---|---|---|---|
| uid | getUid() | string | Unique user ID |
| name | getName() | string | Display name of the user |
| avatar | getAvatar() | string | URL of the user’s avatar image |
| status | getStatus() | string | Online status of the user |
| lastActiveAt | getLastActiveAt() | number | Timestamp when the user was last active |
| role | getRole() | string | Role assigned to the user |
Get the Logged-In User
UsegetLoggedinUser() to get the current user’s details. Resolves with null if no user is logged in.
- TypeScript
- JavaScript
User object with the logged-in user’s information
Retrieve List of Users
In order to fetch the list of users, you can use theUsersRequest class. To use this class i.e to create an object of the UsersRequest class, you need to use the UsersRequestBuilder class. The UsersRequestBuilder class allows you to set the parameters based on which the users are to be fetched.
Fetching using this builder will return User objects
The UsersRequestBuilder class allows you to set the below parameters:
Set Limit
Sets the number of users to fetch per request.- TypeScript
- JavaScript
Set Search Keyword
Filters users by a search string.- TypeScript
- JavaScript
Search In
Specifies which user properties to search. Works withsetSearchKeyword(). By default, searches both UID and name.
- TypeScript
- JavaScript
Set Status
Filters users by online status:CometChat.USER_STATUS.ONLINE— Only online usersCometChat.USER_STATUS.OFFLINE— Only offline users
- TypeScript
- JavaScript
| Field | Getter | Return Type | Description |
|---|---|---|---|
| status | getStatus() | string | Online status of the user ("online" or "offline") |
Hide Blocked Users
Whentrue, excludes users blocked by the logged-in user from the results.
- TypeScript
- JavaScript
Set Roles
Filters users by specified roles.- TypeScript
- JavaScript
| Field | Getter | Return Type | Description |
|---|---|---|---|
| role | getRole() | string | Role assigned to the user |
Friends Only
Whentrue, returns only friends of the logged-in user.
- TypeScript
- JavaScript
Set Tags
Filters users by specified tags.- TypeScript
- JavaScript
| Field | Getter | Return Type | Description |
|---|---|---|---|
| tags | getTags() | string[] | Tags associated with the user |
With Tags
Whentrue, includes tag data in the returned user objects.
- TypeScript
- JavaScript
| Field | Getter | Return Type | Description |
|---|---|---|---|
| tags | getTags() | string[] | Tags associated with the user |
Set UIDs
Fetches specific users by their UIDs. Maximum 25 users per request.- TypeScript
- JavaScript
Sort By
Sorts the user list by a specific property. Default sort order:status → name → UID. Pass "name" to sort by name → UID.
- TypeScript
- JavaScript
Sort By Order
Sets the sort order. Default is ascending ("asc"). Use "desc" for descending.
- TypeScript
- JavaScript
build() to get the UsersRequest object, then call fetchNext() to retrieve users.
- TypeScript
- JavaScript
fetchNext() method returns an array of User objects.
Retrieve Particular User Details
UsegetUser() to fetch a specific user’s details by UID.
- TypeScript
- JavaScript
| Parameter | Description |
|---|---|
| UID | The UID of the user to fetch |
User object containing the details of the user.
Get Online User Count
UsegetOnlineUserCount() to get the total number of online users in your app.
- TypeScript
- JavaScript
Next Steps
User Presence
Track and subscribe to user online/offline status
Block Users
Block and unblock users from your application
User Management
Create, update, and delete users programmatically
Retrieve Conversations
Fetch conversation lists for your chat UI