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.
- TypeScript
- JavaScript
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.- 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
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
Friends Only
Whentrue, returns only friends of the logged-in user.
- TypeScript
- JavaScript
Set Tags
Filters users by specified tags.- TypeScript
- JavaScript
With Tags
Whentrue, includes tag data in the returned user objects.
- TypeScript
- JavaScript
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. 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.
- TypeScript
- JavaScript
| 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.
- TypeScript
- JavaScript
Next Steps
User Presence
Track and subscribe to user online/offline status
Block Users
Block and unblock users from your application