Skip to main content

Documentation Index

Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt

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

// Fetch groups list
const request = new CometChat.GroupsRequestBuilder()
  .setLimit(30).build();
const groups = await request.fetchNext();

// Get specific group details
const group = await CometChat.getGroup("GUID");

// Fetch only joined groups
const joinedRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(30).joinedOnly(true).build();

// Get online member count
const count = await CometChat.getOnlineGroupMemberCount(["GUID"]);
Fetch the list of Group objects the logged-in user can see, get details for a specific group, or check online member counts.

Retrieve List of Groups

Use GroupsRequestBuilder to fetch groups with filtering, searching, and pagination. Fetching using this builder will return Group objects.

Set Limit

Sets the number of groups to fetch per request.
let limit: number = 30;
let groupsRequest: CometChat.GroupsRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(limit)
  .build();

Set Search Keyword

Filters groups by a search string.
let limit: number = 30;
let searchKeyword: string = "group";
let groupsRequest: CometChat.GroupsRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(limit)
  .setSearchKeyword(searchKeyword)
  .build();

Joined Only

When true, returns only groups the logged-in user has joined.
let limit: number = 30;
let groupsRequest: CometChat.GroupsRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(limit)
  .joinedOnly(true)
  .build();

Set Tags

Filters groups by specified tags.
let limit: number = 30;
let tags: Array<String> = ["tag1", "tag2"];
let groupsRequest: CometChat.GroupsRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(limit)
  .setTags(tags)
  .build();

With Tags

When true, includes tag data in the returned group objects.
let limit: number = 30;
let groupsRequest: CometChat.GroupsRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(limit)
  .withTags(true)
  .build();
Relevant fields to access on returned groups:
FieldGetterReturn TypeDescription
tagsgetTags()string[]Tags associated with the group
After configuring the builder, call build() to get the GroupsRequest object, then call fetchNext() to retrieve groups.
The list only includes public and password-protected groups. Private groups appear only if the user is a member.
let limit: number = 30;
let groupsRequest: CometChat.GroupsRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(limit)
  .build();

groupsRequest.fetchNext().then(
  (groupList: CometChat.Group[]) => {
      console.log("Groups list fetched successfully", groupList);
  }, (error: CometChat.CometChatException) => {
      console.log("Groups list fetching failed with error", error);
  }
);
The fetchNext() method returns an array of Group objects.

Retrieve Particular Group Details

Use getGroup() to fetch a specific group’s details by GUID.
const GUID: string = "GUID";
CometChat.getGroup(GUID).then(
  (group: CometChat.Group) => {
      console.log("Group details fetched successfully:", group);
  }, (error: CometChat.CometChatException) => {
      console.log("Group details fetching failed with exception:", error);
  }
);
ParameterDescription
GUIDThe GUID of the group to fetch
The method returns a Group object.

Get Online Group Member Count

Use getOnlineGroupMemberCount() to get the number of online members in specified groups.
let guids: String[] = ["cometchat-guid-1"];
CometChat.getOnlineGroupMemberCount(guids).then(
  (groupMemberCount: Object) => {
      console.log("Total online user for specified groups:", groupMemberCount);
  }, (error: CometChat.CometChatException) => {
      console.log("Online group member count fetching failed with error:", error);
  }
);
Returns an object with GUIDs as keys and online member counts as values. getOnlineGroupMemberCount() resolves with a { guid: count } object where each key is a group GUID and its value is the number of currently online members in that group.

Next Steps

Create Group

Create public, private, or password-protected groups

Retrieve Group Members

Fetch and filter members of a specific group