Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

// Create a group
Group group = Group(guid: "GUID", name: "Group Name", type: CometChatGroupType.public);
await CometChat.createGroup(
  group: group,
  onSuccess: (Group group) => debugPrint("Created: ${group.name}"),
  onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
);

// Create group with members
CometChat.createGroupWithMembers(
  group: group,
  groupMembers: [GroupMember(uid: "UID", scope: GroupMemberScope.participant)],
  bannedUserIds: [],
  onSuccess: (Group group) => debugPrint("Created with members: ${group.name}"),
  onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
);
Group types: CometChatGroupType.public | CometChatGroupType.password | CometChatGroupType.private Member scopes: GroupMemberScope.admin | GroupMemberScope.moderator | GroupMemberScope.participant
Create groups for multi-user conversations. You can create a group on its own with createGroup(), or create one and add members in a single call with createGroupWithMembers(). See the Group Class reference at the bottom for all available fields.

Create a Group

In other words, as a logged-in user, how do I create a public, private or password-protected group?
Available via: SDK | REST API | UI Kits
Use createGroup() to create a new group. Pass a Group object with the group details.
Group TypeConstantDescription
PublicCometChatGroupType.publicAny user can join
PasswordCometChatGroupType.passwordUsers must provide the correct password
PrivateCometChatGroupType.privateUsers must be added by an admin/moderator

Parameters

ParameterTypeDescription
groupGroupAn instance of the Group class containing group details (guid, name, type, password)
onSuccessFunction(Group group)?Callback triggered on successful group creation
onErrorFunction(CometChatException excep)?Callback triggered on error
String GUID = "GUID";
  String groupName = "Hello Group!";
  String groupType = CometChatGroupType.public;
  String password = "";

  Group _group = Group(guid: GUID, name: groupName, type: groupType);


  await CometChat.createGroup(group: _group, onSuccess: (Group group ){
    debugPrint("Group Created Successfully : $group ");
  }, onError:(CometChatException e) {
    debugPrint("Group Creation failed with exception: ${e.message}");
  } );
On Success — A Group object containing all details of the newly created group:Group Object:
ParameterTypeDescriptionSample Value
guidstringUnique identifier for the group"cometchat-guid-1"
namestringDisplay name of the group"Hello Group!"
iconstringURL of the group iconnull
descriptionstringDescription of the groupnull
membersCountnumberNumber of members in the group1
metadataobjectCustom metadata attached to the group{}
joinedAtnumberEpoch timestamp when the logged-in user joined the group1745554729
hasJoinedbooleanWhether the logged-in user has joined the grouptrue
createdAtnumberEpoch timestamp when the group was created1745554729
ownerstringUID of the group owner"cometchat-uid-1"
updatedAtnumberEpoch timestamp when the group was last updated1745554729
tagsarrayList of tags associated with the group[]
typestringType of the group (public, private, password)"public"
scopestringScope of the logged-in user in the group"admin"
passwordstringPassword for password-protected groupsnull
isBannedFromGroupbooleanWhether the logged-in user is banned from the groupfalse
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_GUID_NOT_FOUND"
messagestringHuman-readable error message"The specified group does not exist."
detailsstringAdditional technical details"Please provide a valid GUID for the group."
On success, returns a Group object with the created group’s details.
GUID can be alphanumeric with underscore and hyphen. Spaces, punctuation and other special characters are not allowed.

Add Members While Creating a Group

Use createGroupWithMembers() to create a group and add members in one operation.

Parameters

ParameterTypeDescription
groupGroupThe Group object with group details (guid, name, type, password)
groupMembersList<GroupMember>List of GroupMember objects to add during creation
bannedUserIdsList<String>List of UIDs to ban upon creation (defaults to empty)
onSuccessFunction(Group group)?Callback triggered on successful creation
onErrorFunction(CometChatException excep)?Callback triggered on error
Create a GroupMember with: GroupMember(uid: "UID", scope: GroupMemberScope.participant)
String GUID = "cometchat-guid-11";
String groupName = "Hello Group!";
String groupType = CometChatGroupType.public;

Group group = Group(guid: GUID, name: groupName, type: groupType);
List<GroupMember> members = [
  GroupMember(uid: "cometchat-uid-1", scope: GroupMemberScope.participant),
];
List<String> bannedUserIds = ["cometchat-uid-2"];

CometChat.createGroupWithMembers(
  group: group,
  groupMembers: members,
  bannedUserIds: bannedUserIds,
  onSuccess: (Group group) {
    debugPrint("Group created with members: ${group.name}");
  },
  onError: (CometChatException e) {
    debugPrint("Error creating group with members: ${e.message}");
  },
);
On Success — A Group object containing all details of the newly created group:Group Object:
ParameterTypeDescriptionSample Value
guidstringUnique identifier for the group"cometchat-guid-11"
namestringDisplay name of the group"Hello Group!"
iconstringURL of the group iconnull
descriptionstringDescription of the groupnull
membersCountnumberNumber of members in the group2
metadataobjectCustom metadata attached to the group{}
joinedAtnumberEpoch timestamp when the logged-in user joined the group1745554729
hasJoinedbooleanWhether the logged-in user has joined the grouptrue
createdAtnumberEpoch timestamp when the group was created1745554729
ownerstringUID of the group owner"cometchat-uid-1"
updatedAtnumberEpoch timestamp when the group was last updated1745554729
tagsarrayList of tags associated with the group[]
typestringType of the group (public, private, password)"public"
scopestringScope of the logged-in user in the group"admin"
passwordstringPassword for password-protected groupsnull
isBannedFromGroupbooleanWhether the logged-in user is banned from the groupfalse
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_GUID_NOT_FOUND"
messagestringHuman-readable error message"The specified group does not exist."
detailsstringAdditional technical details"Please provide a valid GUID for the group."

Group Class

The Group object has the following fields. Fields marked “Yes” in the Editable column can be modified after creation using updateGroup().
FieldEditableInformation
guidNeeds to be specified at group creation. Cannot be edited laterA unique identifier for a group
nameYesName of the group
typeNoType of the group: Can be 1. Public 2. Password 3. Private
passwordNoPassword for the group in case the group is of type password.
iconYesAn URL to group icon
descriptionYesDescription about the group
ownerYesUID of the owner of the group.
metadataYesAdditional data for the group as JSON
createdAtNoThe unix timestamp of the time the group was created
updatedAtNoThe unix timestamp of the time the group was last updated
hasJoinedNoA boolean to determine if the logged in user is a member of the group.
joinedAtNoThe unix timestamp of the time the logged in user joined the group.
scopeYesScope of the logged in user. Can be: 1. Admin 2. Moderator 3. Participant
membersCountNoThe number of members in the groups
tagsYesA list of tags to identify specific groups.

Next Steps

Join a Group

Join public, private, or password-protected groups

Add Members

Add users to an existing group

Retrieve Groups

Fetch and filter group lists

Groups Overview

Overview of all group management features