AI Integration Quick Reference
AI Integration Quick Reference
| Field | Value |
|---|---|
| Kotlin (XML Views) | com.cometchat:chat-uikit-kotlin |
| Jetpack Compose | com.cometchat:chat-uikit-compose |
| Import | com.cometchat.uikit.core.events.CometChatEvents |
| Event flows | CometChatEvents.messageEvents, CometChatEvents.callEvents, CometChatEvents.conversationEvents, CometChatEvents.groupEvents, CometChatEvents.userEvents, CometChatEvents.uiEvents |
| Pattern | Kotlin SharedFlow with sealed class event types — collect in viewModelScope or lifecycleScope |
| Purpose | Decoupled communication between UI Kit components — subscribe to event flows to react to changes without direct component references |
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:chat-uikit-kotlinorcom.cometchat:chat-uikit-composedependency 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:
| Flow | Sealed Class | Description |
|---|---|---|
CometChatEvents.messageEvents | MessageEvent | Message sent, edited, deleted, read, reactions |
CometChatEvents.callEvents | CallEvent | Call initiated, accepted, rejected, ended |
CometChatEvents.conversationEvents | ConversationEvent | Conversation deleted, updated |
CometChatEvents.groupEvents | GroupEvent | Group created, deleted, member changes |
CometChatEvents.userEvents | UserEvent | User blocked, unblocked |
CometChatEvents.uiEvents | UIEvent | Panel visibility, active chat changes |
API reference
Message Events
CometChatEvents.messageEvents emits MessageEvent sealed class instances when messages are sent, edited, deleted, or read.
Event types:
| Event | Description |
|---|---|
MessageEvent.Sent(message, status) | Triggered when a message is sent. Status can be inProgress or sent. |
MessageEvent.Edited(message, status) | Triggered when a message is edited. Status can be inProgress or sent. |
MessageEvent.Deleted(message) | Triggered when a message is deleted. |
MessageEvent.Read(message) | Triggered when a message is read. |
MessageEvent.LiveReaction(icon) | Triggered when a live reaction is sent. |
MessageEvent.FormReceived(message) | Triggered when a form message is received. |
MessageEvent.CardReceived(message) | Triggered when a card message is received. |
MessageEvent.CustomInteractiveReceived(message) | Triggered when a custom interactive message is received. |
MessageEvent.InteractionGoalCompleted(message) | Triggered when an interaction goal is completed. |
MessageEvent.SchedulerReceived(message) | Triggered when a scheduler message is received. |
- 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:
| Event | Description |
|---|---|
CallEvent.OutgoingCall(call) | Triggered when the logged-in user initiates an outgoing call. |
CallEvent.Accepted(call) | Triggered when a call is accepted. |
CallEvent.Rejected(call) | Triggered when a call is rejected. |
CallEvent.Ended(call) | Triggered when a call is ended. |
- Kotlin (XML Views)
- Jetpack Compose
Conversation Events
CometChatEvents.conversationEvents emits ConversationEvent sealed class instances when conversations are deleted or updated.
Event types:
| Event | Description |
|---|---|
ConversationEvent.Deleted(conversation) | Triggered when the logged-in user deletes a conversation. |
ConversationEvent.Updated(conversation) | Triggered when there is an update in the conversation. |
- 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:
| Event | Description |
|---|---|
GroupEvent.Created(group) | Triggered when the logged-in user creates a group. |
GroupEvent.Deleted(group) | Triggered when the logged-in user deletes a group. |
GroupEvent.Left(actionMessage, leftUser, leftGroup) | Triggered when the logged-in user leaves a group. |
GroupEvent.MemberScopeChanged(actionMessage, updatedUser, scopeChangedTo, scopeChangedFrom, group) | Triggered when a member’s scope is changed. |
GroupEvent.MemberBanned(actionMessage, bannedUser, bannedBy, bannedFrom) | Triggered when a member is banned from a group. |
GroupEvent.MemberKicked(actionMessage, kickedUser, kickedBy, kickedFrom) | Triggered when a member is kicked from a group. |
GroupEvent.MemberUnBanned(actionMessage, unbannedUser, unBannedBy, unBannedFrom) | Triggered when a member is unbanned from a group. |
GroupEvent.MemberJoined(joinedUser, joinedGroup) | Triggered when the logged-in user joins a group. |
GroupEvent.MemberAdded(actionMessages, usersAdded, userAddedIn, addedBy) | Triggered when members are added to a group. |
GroupEvent.OwnershipChanged(group, newOwner) | Triggered when group ownership is transferred. |
- 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:
| Event | Description |
|---|---|
UserEvent.Blocked(user) | Triggered when the logged-in user blocks another user. |
UserEvent.Unblocked(user) | Triggered when the logged-in user unblocks another user. |
- Kotlin (XML Views)
- Jetpack Compose
UI Events
CometChatEvents.uiEvents emits UIEvent sealed class instances for UI-level actions such as panel visibility and active chat changes.
Event types:
| Event | Description |
|---|---|
UIEvent.ShowPanel(id, alignment, view) | Triggered to show an additional UI panel with custom elements. |
UIEvent.HidePanel(id, alignment) | Triggered to hide a previously shown UI panel. |
UIEvent.ActiveChatChanged(id, message, user, group) | Triggered when the active chat changes. |
UIEvent.OpenChat(user, group) | Triggered to open a chat with a specific user or group. |
- Kotlin (XML Views)
- Jetpack Compose
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