AI Agent Component Spec
AI Agent Component Spec
| Field | Value |
|---|---|
| Package | @cometchat/chat-uikit-react |
| Key components | CometChatMessages, CometChatGroupMembers, CometChatMessageComposer, CometChatMessageList, CometChatMessageHeader |
| Init | CometChatUIKit.init(UIKitSettings) then CometChatUIKit.login("UID") |
| Purpose | Launch a direct 1:1 chat from a group member profile |
| Sample app | GitHub |
| Related | All Guides |
Components
| Component / Class | Role |
|---|---|
CometChatGroupMembers | Displays group members with click handlers for private messaging |
CometChatMessageComposer | Input component for composing private messages |
CometChatMessageList | Displays private conversation messages |
CometChatMessageHeader | Header showing private chat information |
Integration Steps
1. Group Member Click Handler
When a group member is clicked, cast them to aUser object and initiate a private chat. The current group is saved so the user can return to it later. CometChat.getConversation() fetches or creates the 1:1 conversation.
File: CometChatHome.tsx
2. Group Members with Private Messaging Option
Add a “Message Privately” option to the group members list. Theoptions prop adds a context-menu action that triggers the private chat flow when clicked.
File: CometChatHome.tsx
3. Private Chat Interface
Render a full chat view (header, message list, composer) for the 1:1 conversation. The header includes a back button that returns the user to the original group, and a subtitle showing which group the private chat was initiated from. File: CometChatHome.tsx4. State Management
Add reducer cases to track the group the user came from, whether the private chat is visible, and which user is being messaged. This lets the app restore the group context when the user navigates back. File: appReducer.tsFeature Matrix
| Feature | Component / Method | File |
|---|---|---|
| Group member selection | CometChatGroupMembers | CometChatHome.tsx |
| Private chat initiation | startPrivateChatFromGroup() | CometChatHome.tsx |
| Private chat interface | PrivateChatFromGroupView | CometChatHome.tsx |
| Context preservation | updatePreviousGroup | appReducer.ts |
| Return to group | returnToGroup() | CometChatHome.tsx |
| Member options | options in CometChatGroupMembers | CometChatHome.tsx |
| State management | updateShowPrivateChat | appReducer.ts |