AI Integration Quick Reference
// Create a group
let group = new CometChat . Group ( "GUID" , "Group Name" , CometChat . GROUP_TYPE . PUBLIC , "" );
let createdGroup = await CometChat . createGroup ( group );
// Create group with members
let members = [ new CometChat . GroupMember ( "UID" , CometChat . GROUP_MEMBER_SCOPE . PARTICIPANT )];
let result = await CometChat . createGroupWithMembers ( group , members , []);
Group types: PUBLIC | PASSWORD | PRIVATE
Member scopes: ADMIN | MODERATOR | PARTICIPANT
Create a Group
Use createGroup() to create a new group. Pass a Group object with the group details.
Group constructors:
new Group(GUID, name, groupType, password)
new Group(GUID, name, groupType, password, icon, description)
Group types:
CometChat.GROUP_TYPE.PUBLIC
CometChat.GROUP_TYPE.PASSWORD
CometChat.GROUP_TYPE.PRIVATE
JavaScript
TypeScript
Async/Await
const GUID = "GUID" ;
const groupName = "Hello Group!" ;
const groupType = CometChat . GROUP_TYPE . PUBLIC ;
const password = "" ;
const group = new CometChat . Group ( GUID , groupName , groupType , password );
CometChat . createGroup ( group ). then (
group => {
console . log ( "Group created successfully:" , group );
}, error => {
console . log ( "Group creation failed with exception:" , error );
}
);
const GUID : string = "GUID" ;
const groupName : string = "Hello Group!" ;
const groupType : string = CometChat . GROUP_TYPE . PUBLIC ;
const password : string = "" ;
const group : CometChat . Group = new CometChat . Group ( GUID , groupName , groupType , password );
CometChat . createGroup ( group ). then (
( group : CometChat . Group ) => {
console . log ( "Group created successfully:" , group );
}, ( error : CometChat . CometChatException ) => {
console . log ( "Group creation failed with exception:" , error );
}
);
const GUID = "GUID" ;
const groupName = "Hello Group!" ;
const groupType = CometChat . GROUP_TYPE . PUBLIC ;
const password = "" ;
const group = new CometChat . Group ( GUID , groupName , groupType , password );
try {
const createdGroup = await CometChat . createGroup ( group );
console . log ( "Group created successfully:" , createdGroup );
} catch ( error ) {
console . log ( "Group creation failed with exception:" , error );
}
Parameter Description groupAn instance of Group class
On success, returns a Group object with the created group’s details.
The method returns a Group object. Access the response data using getter methods:
Field Getter Return Type Description guid getGuid()stringUnique group ID name getName()stringDisplay name of the group type getType()stringGroup type ("public", "private", or "password") owner getOwner()stringUID of the group owner membersCount getMembersCount()numberTotal number of members in the group createdAt getCreatedAt()numberTimestamp when the group was created
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:
group — The Group object
members — Array of GroupMember objects to add
bannedMembers — Array of UIDs to ban (can be empty)
Create a GroupMember with: new CometChat.GroupMember(UID, scope)
JavaScript
TypeScript
Async/Await
let GUID = "cometchat-guid-11" ;
let UID = "cometchat-uid-1" ;
let groupName = "Hello Group!" ;
let groupType = CometChat . GROUP_TYPE . PUBLIC ;
let group = new CometChat . Group ( GUID , groupName , groupType );
let members = [
new CometChat . GroupMember ( UID , CometChat . GROUP_MEMBER_SCOPE . PARTICIPANT )
];
let banMembers = [ "cometchat-uid-2" ];
CometChat . createGroupWithMembers ( group , members , banMembers ). then (
response => {
console . log ( "Group created successfully" , response );
}, error => {
console . log ( "Some error occured while creating group" , error )
}
);
let GUID : string = "cometchat-guid-11" ;
let UID : string = "cometchat-uid-1" ;
let groupName : string = "Hello Group!" ;
let groupType : string = CometChat . GROUP_TYPE . PUBLIC ;
let group : CometChat . Group = new CometChat . Group ( GUID , groupName , groupType );
let members : Array < CometChat . GroupMember > = [
new CometChat . GroupMember ( UID , CometChat . GROUP_MEMBER_SCOPE . PARTICIPANT )
];
let banMembers : Array < String > = [ "cometchat-uid-2" ];
CometChat . createGroupWithMembers ( group , members , banMembers ). then (
( response : Object ) => {
console . log ( "Group created successfully" , response );
}, ( error : CometChat . CometChatException ) => {
console . log ( "Some error occured while creating group" , error )
}
);
let GUID = "cometchat-guid-11" ;
let UID = "cometchat-uid-1" ;
let groupName = "Hello Group!" ;
let groupType = CometChat . GROUP_TYPE . PUBLIC ;
let group = new CometChat . Group ( GUID , groupName , groupType );
let members = [
new CometChat . GroupMember ( UID , CometChat . GROUP_MEMBER_SCOPE . PARTICIPANT )
];
let banMembers = [ "cometchat-uid-2" ];
try {
const response = await CometChat . createGroupWithMembers ( group , members , banMembers );
console . log ( "Group created successfully" , response );
} catch ( error ) {
console . log ( "Some error occured while creating group" , error );
}
Returns an object with two keys:
group — The created Group object
members — Object with UIDs as keys and "success" or error message as values
Group Class
Field Editable Information guid Needs to be specified at group creation. Cannot be edited later A unique identifier for a group name Yes Name of the group type No Type of the group: Can be 1. Public 2. Password 3. Private password No Password for the group in case the group is of type password. icon Yes An URL to group icon description Yes Description about the group owner Yes UID of the owner of the group. metadata Yes Additional data for the group as JSON createdAt No The unix timestamp of the time the group was created updatedAt No The unix timestamp of the time the group was last updated hasJoined No A boolean to determine if the logged in user is a member of the group. joinedAt No The unix timestamp of the time the logged in user joined the group. scope Yes Scope of the logged in user. Can be: 1. Admin 2. Moderator 3. Participant membersCount No The number of members in the groups tags Yes A 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