AI Integration Quick Reference
AI Integration Quick Reference
Retrieve Logged In User Details
UsegetLoggedInUser() to get the current user’s details. This method also verifies if a user is logged in — a rejected promise indicates no user is logged in.
- Get Logged In User Details
- TypeScript
User object with the logged-in user’s information.
The method returns a User object. Access the response data using getter methods:
| 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 |
Retrieve List of Users
UseUsersRequestBuilder to fetch users with filtering, searching, and pagination.
Set Limit
Sets the number of users to fetch per request.- Set Limit
- TypeScript
Set Search Keyword
Filters users by a search string.- Set Search Keyword
- TypeScript
Search In
Specifies which user properties to search. Works withsetSearchKeyword(). By default, searches both UID and name.
- JavaScript
- TypeScript
Set Status
Filters users by online status:CometChat.USER_STATUS.ONLINE— Only online usersCometChat.USER_STATUS.OFFLINE— Only offline users
- Set Status
- TypeScript
Hide Blocked Users
Whentrue, excludes users blocked by the logged-in user from the results.
- Hide Blocked Users
- TypeScript
Set Roles
Filters users by specified roles.- Set Roles
- TypeScript
Friends Only
Whentrue, returns only friends of the logged-in user.
- Friends Only
- TypeScript
Set Tags
Filters users by specified tags.- TypeScript
With Tags
Whentrue, includes tag data in the returned user objects.
- TypeScript
Set UIDs
Fetches specific users by their UIDs. Maximum 25 users per request.- Set UIDs
- TypeScript
Sort By
Sorts the user list by a specific property. Default sort order:status → name → UID. Pass "name" to sort by name → UID.
- JavaScript
- TypeScript
Sort By Order
Sets the sort order. Default is ascending ("asc"). Use "desc" for descending.
- JavaScript
- TypeScript
build() to get the UsersRequest object, then call fetchNext() to retrieve users.
- JavaScript
- TypeScript
fetchNext() method returns an array of User objects. Access the response data using getter methods:
| 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 |
Retrieve Particular User Details
UsegetUser() to fetch a specific user’s details by UID.
- Retrieve Particular User's Details
- TypeScript
| Parameter | Description |
|---|---|
| UID | The UID of the user to fetch |
User object with the user’s details.
The method returns a User object. Access the response data using getter methods:
| 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 Online User Count
UsegetOnlineUserCount() to get the total number of online users in your app.
- Get Online User Count
- TypeScript
Next Steps
User Presence
Track and subscribe to user online/offline status
Block Users
Block and unblock users from your application