AI Integration Quick Reference
AI Integration Quick Reference
| Field | Value |
|---|---|
| Package | @cometchat/chat-uikit-react |
| Import | import { CometChatUIKit } from "@cometchat/chat-uikit-react"; |
| Init | CometChatUIKit.init(UIKitSettings) |
| Login (dev) | CometChatUIKit.login("UID") |
| Login (prod) | CometChatUIKit.loginWithAuthToken("AUTH_TOKEN") |
| Other methods | CometChatUIKit.logout(), CometChatUIKit.getLoggedinUser(), CometChatUIKit.createUser(user), CometChatUIKit.updateUser(user) |
| Send messages | CometChatUIKit.sendTextMessage(), CometChatUIKit.sendMediaMessage(), CometChatUIKit.sendCustomMessage() |
| Note | Use these wrapper methods instead of raw SDK calls — they manage internal UI Kit eventing |
Methods
All methods are accessed via theCometChatUIKit class.
Init
Initializes the CometChat JavaScript SDK. Must be called on app startup before any other UI Kit method.Replace
APP_ID, REGION, and AUTH_KEY with values from the CometChat Dashboard. Auth Key is optional — use Auth Token for production.- JavaScript
Setting Session Storage Mode
To use session storage instead of the default local storage, configure it during initialization:- JavaScript
- TypeScript
Get Logged In User
Checks for an existing session in the SDK. Returns the logged-in user details ornull.
- JavaScript
Login using Auth Key
Simple authentication for development/POC. For production, use Auth Token.- JavaScript
- TypeScript
Login using Auth Token
Production-safe authentication that does not expose the Auth Key in client code.- Create a User via the CometChat API when the user signs up in your app.
- Create an Auth Token via the CometChat API for the new user and save the token in your database.
- Load the Auth Token in your client and pass it to the
loginWithAuthToken()method.
- JavaScript
- TypeScript
Logout
Ends the current user session.- JavaScript
Create user
Takes aUser object and Auth Key, returns the created User object.
- JavaScript
- TypeScript
Update user
Takes aUser object and Auth Key, returns the updated User object.
- JavaScript
- TypeScript
Base Message
Text message
Sends a text message in a 1:1 or group chat. Takes aTextMessage object.
- 1:1 chat
- Group chat
Media message
Sends a media message in a 1:1 or group chat. Takes aMediaMessage object.
Replace
INPUT FILE OBJECT with the actual File object.- 1:1 chat
- Group chat
Custom message
Sends a custom message (neither text nor media) in a 1:1 or group chat. Takes aCustomMessage object.
- 1:1 chat
- Group chat