AI Agent Component Spec
AI Agent Component Spec
| Field | Value |
|---|---|
| Package | com.cometchat:chat-uikit-android |
| Key components | CometChatMessageList, CometChatMessageComposer, CometChatMessageHeader, CometChat.sendMessage() |
| Purpose | Allow users to start a private one-on-one chat from a user profile or list screen. |
| Related | Message List, Message Composer, Message Header, All Guides |
Overview
The Message Privately feature streamlines direct messaging by enabling:- Quick entry into a one-on-one conversation from a user context.
- Automatic conversation creation if none exists.
- Optional initial message send to surface the chat in lists.
MessagesActivity with the target user’s UID → chat UI loads.
Prerequisites
- Android Studio project with CometChat Android UI Kit v5 (
com.cometchat:chat-uikit-android) added tobuild.gradle. - Valid CometChat App ID, Auth Key, and Region initialized.
<uses-permission android:name="android.permission.INTERNET"/>inAndroidManifest.xml.- Users created in your CometChat app.
- User must be logged in via
CometChatUIKit.login()before invoking this feature. - Existing
MessagesActivitycapable of handling one-on-one chats.
Components
| Component / Class | Responsibility |
|---|---|
UserDetailsActivity | Shows user profile UI and Message Privately button. |
MessagesActivity | Chat screen for one-on-one conversation with a User. |
MainActivity | (Optional) entry point for sending initial message programmatically. |
CometChatUIKit.login() | Authenticates the current user session. |
CometChat.sendMessage() | Sends a dummy text message to initialize conversation. |
Integration Steps
1. Launch One-on-One Chat from Profile
Navigate fromUserDetailsActivity to MessagesActivity with the selected user.
- Kotlin
- Java
UserDetailsActivity.java
2. Handle Incoming Intent in Chat Screen
Deserialize theUser JSON extra and configure the chat UI.
- Kotlin
- Java
MessagesActivity.java
3. (Optional) Programmatically Create Conversation
Send an initial greeting to ensure the chat appears in conversation lists.- Kotlin
- Java
MainActivity.java
Implementation Flow
| Step | Action | Location |
|---|---|---|
| 1 | Tap Message Privately button | UserDetailsActivity.java |
| 2 | Launch MessagesActivity with user JSON extra | UserDetailsActivity onClick listener |
| 3 | Deserialize and bind User to UI Kit components | MessagesActivity.onCreate() |
| 4 | (Optional) Send initial message to surface chat list | MainActivity.sendInitialMessage() |
Customization Options
- Button Text & Style: Update
messagePrivatelyBtninactivity_user_details.xml. - Intent Extras Key: Use a custom key instead of
R.string.app_user. - Dummy Message: Customize initial message content or omit step if undesired.
Edge Cases
| Condition | Behavior |
|---|---|
| User never chatted before | The conversation appears after the first message is sent. |
| Target user blocked | Composer hidden; consider showing unblock prompt. |
| Invalid user data | Guard against null JSON and show error UI or fallback. |
| Missing JSON extra | Do not initialize chat; optionally close screen with warning. |
Summary / Feature Matrix
| Feature | Component / Method |
|---|---|
| Launch private chat | Intent from messagePrivatelyBtn |
| Initialize chat UI | messageHeader.setUser(), messageList.setUser() |
| Create conversation | CometChat.sendMessage() optional |
Android Sample App (Java)
Explore this feature in the CometChat SampleApp:
GitHub → SampleApp
Android Sample App (Kotlin)
Explore this feature in the CometChat SampleApp:
GitHub → SampleApp