Quick Reference for AI Agents & Developers// Join a public group
await CometChat.joinGroup("group_guid", CometChat.GROUP_TYPE.PUBLIC, "");
// Join a password-protected group
await CometChat.joinGroup("group_guid", CometChat.GROUP_TYPE.PASSWORD, "password");
// Check if already a member
const group = await CometChat.getGroup("group_guid");
if (group.getHasJoined()) {
console.log("Already a member");
}
// Listen for join events
CometChat.addGroupListener("GROUP_LISTENER", new CometChat.GroupListener({
onGroupMemberJoined: (message, joinedUser, joinedGroup) => {
console.log(joinedUser.getName(), "joined", joinedGroup.getName());
}
}));
// Note: Private groups require admin to add members (can't join directly)
Join a group to start participating in group conversations. The join process varies based on the group type.
Availability: SDK, API, UI KitsOnce joined, CometChat tracks membership - you don’t need to rejoin each session.
Join a Group
Public Group
Password Group
TypeScript
Async/Await
const GUID = "group-123";
const groupType = CometChat.GROUP_TYPE.PUBLIC;
const password = "";
CometChat.joinGroup(GUID, groupType, password).then(
(group) => console.log("Joined group:", group.getName()),
(error) => console.log("Failed to join:", error)
);
const GUID = "group-123";
const groupType = CometChat.GROUP_TYPE.PASSWORD;
const password = "secret123";
CometChat.joinGroup(GUID, groupType, password).then(
(group) => console.log("Joined group:", group.getName()),
(error) => console.log("Failed to join:", error)
);
const GUID: string = "group-123";
const groupType: string = CometChat.GROUP_TYPE.PUBLIC;
const password: string = "";
CometChat.joinGroup(GUID, groupType, password).then(
(group: CometChat.Group) => console.log("Joined group:", group.getName()),
(error: CometChat.CometChatException) => console.log("Failed:", error)
);
const joinGroup = async () => {
try {
const GUID = "group-123";
const groupType = CometChat.GROUP_TYPE.PUBLIC;
const password = ""; // Use password for PASSWORD type groups
const group = await CometChat.joinGroup(GUID, groupType, password);
console.log("Joined group:", group.getName());
} catch (error) {
console.log("Failed to join:", error);
}
};
| Parameter | Description |
|---|
GUID | Group identifier |
groupType | PUBLIC, PASSWORD, or PRIVATE |
password | Required for PASSWORD groups |
Private groups cannot be joined directly - users must be added by an admin.
Check Membership
Use hasJoined to check if the user is already a member:
const group = await CometChat.getGroup("group-123");
if (group.getHasJoined()) {
console.log("Already a member");
} else {
// Show join button
}
Real-Time Join Events
Listen for when users join groups you’re a member of:
const listenerID = "GROUP_LISTENER";
CometChat.addGroupListener(
listenerID,
new CometChat.GroupListener({
onGroupMemberJoined: (message, joinedUser, joinedGroup) => {
console.log(`${joinedUser.getName()} joined ${joinedGroup.getName()}`);
}
})
);
// Remove listener when done
CometChat.removeGroupListener(listenerID);
Missed Join Events
When fetching message history, join events appear as Action messages:
// In your message list
messages.forEach((message) => {
if (message.getCategory() === "action") {
const action = message.getAction();
if (action === "joined") {
const user = message.getActionBy();
console.log(`${user.getName()} joined the group`);
}
}
});
Next Steps