AI Integration Quick Reference
AI Integration Quick Reference
- User registers in your app → Create user in CometChat
- User logs into your app → Log user into CometChat
Creating a User
User creation should ideally happen on your backend via the REST API. For client-side creation (development only), usecreateUser():
- JavaScript
- TypeScript
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 |
| role | getRole() | string | Role assigned to the user |
| status | getStatus() | string | Online status of the user |
Updating a User
Like creation, user updates should ideally happen on your backend via the REST API. For client-side updates (development only), useupdateUser():
- JavaScript
- TypeScript
User object has the correct UID set.
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 |
| role | getRole() | string | Role assigned to the user |
| metadata | getMetadata() | Object | Custom metadata attached to the user |
Updating Logged-in User
UseupdateCurrentUserDetails() to update the current user without an Auth Key. Note: You cannot update the user’s role with this method.
- JavaScript
- TypeScript
Deleting a User
User deletion is only available via the REST API.User Class
| Field | Editable | Information |
|---|---|---|
| uid | specified on user creation. Not editable after that | Unique identifier of the user |
| name | Yes | Display name of the user |
| avatar | Yes | URL to profile picture of the user |
| link | Yes | URL to profile page |
| role | Yes | User role of the user for role based access control |
| metadata | Yes | Additional information about the user as JSON |
| status | No | Status of the user. Could be either online/offline |
| statusMessage | Yes | Any custom status message that needs to be set for a user |
| lastActiveAt | No | The unix timestamp of the time the user was last active. |
| hasBlockedMe | No | A boolean that determines if the user has blocked the logged in user |
| blockedByMe | No | A boolean that determines if the logged in user has blocked the user |
| tags | Yes | A list of tags to identify specific users |
Next Steps
Retrieve Users
Fetch and filter user lists with pagination.
User Presence
Monitor real-time online/offline status.
Block Users
Block and unblock users.
Authentication
Log users into CometChat.