Goal
By the end of this guide you will have a working group chat interface where users can create a new group, add members, and exchange messages in real time using the CometChat compound components.Prerequisites
- Completed the Integration Guide guide
- A running
CometChatProvidersetup with valid credentials - Familiarity with the Conversations and Message List components
Components Used
| Component / API | Purpose |
|---|---|
CometChatConversations | Lists existing conversations including groups |
CometChatMessageHeader | Displays group name, avatar, and member count |
CometChatMessageList | Renders group messages in real time |
CometChatMessageComposer | Text input for sending messages to the group |
CometChat.createGroup() | SDK method to create a new group |
CometChat.joinGroup() | SDK method to join an existing group |
CometChat.addMembersToGroup() | SDK method to add members |
Step 1: Set up the app shell
Wrap your application inCometChatProvider and create a layout with a sidebar for conversations and a main area for messages.
App.tsx
Step 2: Create a new group
UseCometChat.createGroup() to programmatically create a group. You need a unique GUID, a name, and a group type (public, private, or password-protected).
Step 3: Add members to the group
After creating a group, add members usingCometChat.addMembersToGroup(). Each member needs a UID and a scope (admin, moderator, or participant).
Step 4: Join an existing group
For public groups, users can join without an invite usingCometChat.joinGroup().
Step 5: Display conversations and select a group
UseCometChatConversations to show the user’s conversations. When a group conversation is selected, pass the group object to the message components.
Step 6: Render the group message view
CombineCometChatMessageList and CometChatMessageComposer to display messages and allow sending within the selected group.
Step 7: Add a create-group form
Provide a simple UI for users to create groups on the fly. Wire it to thecreateGroup function from Step 2.
Complete Example
GroupChat.tsx
Next Steps
- Groups — browse and join existing groups
- Group Members — manage group membership
- Message Header — customize the group header
- CometChatProvider — configure the root provider