AI Integration Quick Reference
AI Integration Quick Reference
Overview
CometChatUIKit is a static class that provides imperative methods for SDK initialization, authentication, and message sending. The UI Kit wraps the Chat SDK methods to manage internal eventing and keep UI components synchronized. Use these wrapper methods instead of raw SDK calls.
You must call CometChatUIKit.init() and CometChatUIKit.login() (or loginWithAuthToken()) before mounting CometChatProvider. These methods are also useful for:
- Sending messages programmatically outside the composer
- Checking initialization/login state
Initialization
CometChatUIKit.init(settings)
Initialize the CometChat SDK and UIKit.
Returns:
Promise<CometChat.User | null> — the logged-in user if a session exists, otherwise null.
What it does:
- Initializes the CometChat SDK with app settings
- Sets source metadata for analytics
- Creates the plugin registry (default + user plugins)
- Initializes the localization singleton
- Resumes existing session (if any)
- Initializes Calls SDK (if enabled)
Setting Session Storage Mode
By default, session data is stored inlocalStorage. To use sessionStorage instead, configure it during initialization via the UIKitSettingsBuilder:
sessionStorage, configure it in your UIKitSettingsBuilder before calling CometChatUIKit.init():
Session storage is cleared when the browser tab is closed. Use this mode if you want users to re-authenticate on every new tab/session.
Authentication
CometChatUIKit.login(uid)
Log in a user by UID. Requires authKey in UIKitSettings.
Returns:
Promise<CometChat.User>
CometChatUIKit.loginWithAuthToken(authToken)
Log in with a server-generated auth token. Preferred for production.
Returns:
Promise<CometChat.User>
CometChatUIKit.logout()
Log out the current user.
Promise<void>
User Management
Both methods requireauthKey in your UIKitSettings — they throw if it is missing. Intended for development/testing; in production, create and update users server-side via the REST API.
CometChatUIKit.createUser(user)
Create a new user.
Returns:
Promise<CometChat.User>
CometChatUIKit.updateUser(user)
Update an existing user.
Returns:
Promise<CometChat.User>
State Getters
CometChatUIKit.getLoggedInUser()
Get the currently logged-in user (synchronous).
CometChat.User | null
CometChatUIKit.isInitialized()
Check if the SDK has been initialized.
boolean
CometChatUIKit.isCallingReady()
Check if the Calls SDK is ready.
Returns: boolean
CometChatUIKit.getPluginRegistry()
Get the plugin registry instance.
Returns: CometChatPluginRegistry | null
CometChatUIKit.getSettings()
Get the UIKitSettings used during initialization.
Returns: UIKitSettings | null
CometChatUIKit.getConversationUpdateSettings()
Get conversation update settings fetched from the dashboard.
Returns: CometChat.ConversationUpdateSettings | null
Message Sending
CometChatUIKit.sendTextMessage(message)
Send a text message. Sets muid and sentAt if not already set.
Promise<CometChat.BaseMessage>
CometChatUIKit.sendMediaMessage(message)
Send a media message (image, video, audio, file).
Promise<CometChat.BaseMessage>
CometChatUIKit.sendCustomMessage(message)
Send a custom message (polls, location, etc.).
Promise<CometChat.BaseMessage>