AI Integration Quick Reference
AI Integration Quick Reference
CometChatEvents singleton, and other parts of your application collect these SharedFlow streams to react without direct references between components.
When to use this
- You need to update your UI when a user is blocked or unblocked.
- You need to respond to group actions such as member joins, kicks, bans, or ownership transfers.
- You need to track conversation deletions or updates in real time.
- You need to react to messages being sent, edited, deleted, or read.
- You need to handle call lifecycle events (outgoing, accepted, rejected, ended).
- You need to respond to UI-level events such as panel visibility changes or active chat changes.
Prerequisites
- The
com.cometchat:chatuikit-kotlin-androidorcom.cometchat:chatuikit-compose-androiddependency added to your project. CometChatUIKit.init()called and completed successfully.- A logged-in CometChat user (call
CometChatUIKit.login()before collecting events).
CometChatEvents Singleton
All events are accessed through theCometChatEvents singleton in chatuikit-core. Each domain has a dedicated SharedFlow that emits sealed class event types:
API reference
Message Events
CometChatEvents.messageEvents emits MessageEvent sealed class instances when messages are sent, edited, deleted, or read.
Event types:
Collecting events:
- Kotlin (XML Views)
- Jetpack Compose
What this does: Collects the messageEvents SharedFlow and pattern-matches on the sealed class to handle each message lifecycle event.
Call Events
CometChatEvents.callEvents emits CallEvent sealed class instances for call lifecycle changes.
Event types:
Collecting events:
- Kotlin (XML Views)
- Jetpack Compose
Conversation Events
CometChatEvents.conversationEvents emits ConversationEvent sealed class instances when conversations are deleted or updated.
Event types:
Collecting events:
- Kotlin (XML Views)
- Jetpack Compose
Group Events
CometChatEvents.groupEvents emits GroupEvent sealed class instances when the logged-in user performs group-related actions.
Event types:
Collecting events:
- Kotlin (XML Views)
- Jetpack Compose
User Events
CometChatEvents.userEvents emits UserEvent sealed class instances when the logged-in user blocks or unblocks another user.
Event types:
Collecting events:
- Kotlin (XML Views)
- Jetpack Compose
UI Events
CometChatEvents.uiEvents emits CometChatUIEvent sealed class instances for UI-level actions such as panel visibility and active chat changes.
Event types:
Collecting events:
- Kotlin (XML Views)
- Jetpack Compose
AboutCardActionClicked: The UI Kit renders card bubbles automatically (CometChatCardBubble) and emits this event when a user taps an action inside one — so a single subscriber handles every card action across your app.event.messageis aCardMessagefor standalone card messages and anAIAssistantMessagefor cards embedded in AI agent replies.event.actionEventis typedAny; import and cast it tocom.cometchat.cards.actions.CometChatCardActionEventto read itsaction,elementId, andcardJson.
Lifecycle Management
SinceSharedFlow collection is coroutine-based, lifecycle management is handled automatically:
- In XML Views, use
lifecycleScope.launch— the coroutine is cancelled when the lifecycle owner is destroyed. - In Jetpack Compose, use
LaunchedEffect— the coroutine is cancelled when the composable leaves the composition.
removeListener calls are needed, unlike the old static listener pattern.
Next steps
Methods Reference
UI Kit wrapper methods for initialization, authentication, and sending messages
Conversations
Display and manage the conversation list, which reacts to conversation events
Message List
Display messages in a chat, which reacts to message events