Skip to main content
Quick Reference for AI Agents & Developers
// Fetch groups list
const groupsRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(30)
  .build();
const groups = await groupsRequest.fetchNext();

// Get joined groups only
const groupsRequest = new CometChat.GroupsRequestBuilder()
  .joinedOnly(true)
  .build();

// Search groups
const groupsRequest = new CometChat.GroupsRequestBuilder()
  .setSearchKeyword("team")
  .build();

// Filter by tags
const groupsRequest = new CometChat.GroupsRequestBuilder()
  .setTags(["engineering", "product"])
  .withTags(true)
  .build();

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

// Get online member count
const counts = await CometChat.getOnlineGroupMemberCount(["guid1", "guid2"]);
Retrieve group information including group lists, individual group details, and online member counts.
Availability: SDK, API, UI KitsPublic and password groups are visible to all users. Private groups are only visible to members.

Fetch Group List

Use GroupsRequestBuilder to fetch groups with various filters:
const limit = 30;

const groupsRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(limit)
  .build();

groupsRequest.fetchNext().then(
  (groupList) => console.log("Groups:", groupList),
  (error) => console.log("Failed:", error)
);

Builder Options

MethodDescription
setLimit(limit)Number of groups per request (max 100)
setSearchKeyword(keyword)Search groups by name
joinedOnly(true)Only return groups user has joined
setTags(tags)Filter by group tags
withTags(true)Include tags in response

Get Joined Groups Only

Fetch only groups the user is a member of:
const groupsRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(30)
  .joinedOnly(true)
  .build();

groupsRequest.fetchNext().then(
  (groupList) => console.log("My groups:", groupList),
  (error) => console.log("Failed:", error)
);

Search Groups

const groupsRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(30)
  .setSearchKeyword("team")
  .build();

groupsRequest.fetchNext().then(
  (groupList) => console.log("Search results:", groupList),
  (error) => console.log("Failed:", error)
);

Filter by Tags

const groupsRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(30)
  .setTags(["engineering", "product"])
  .withTags(true)  // Include tags in response
  .build();

groupsRequest.fetchNext().then(
  (groupList) => {
    groupList.forEach((group) => {
      console.log(group.getName(), "Tags:", group.getTags());
    });
  },
  (error) => console.log("Failed:", error)
);

Get Single Group

Fetch details for a specific group:
const GUID = "group-123";

CometChat.getGroup(GUID).then(
  (group) => {
    console.log("Name:", group.getName());
    console.log("Type:", group.getType());
    console.log("Members:", group.getMembersCount());
    console.log("Has Joined:", group.getHasJoined());
  },
  (error) => console.log("Failed:", error)
);

Get Online Member Count

Get the count of online members in specific groups:
const guids = ["group-123", "group-456"];

CometChat.getOnlineGroupMemberCount(guids).then(
  (counts) => {
    console.log("Online counts:", counts);
    // { "group-123": 5, "group-456": 12 }
  },
  (error) => console.log("Failed:", error)
);

Pagination

Use fetchNext() repeatedly to paginate through results:
class GroupListManager {
  constructor() {
    this.groupsRequest = new CometChat.GroupsRequestBuilder()
      .setLimit(30)
      .build();
    this.groups = [];
  }

  async loadMore() {
    try {
      const groupList = await this.groupsRequest.fetchNext();
      this.groups = [...this.groups, ...groupList];
      return groupList;
    } catch (error) {
      console.log("Failed to load groups:", error);
      return [];
    }
  }
}

// Usage
const manager = new GroupListManager();
const firstPage = await manager.loadMore();
const secondPage = await manager.loadMore();

Group Properties

PropertyTypeDescription
guidStringUnique identifier
nameStringDisplay name
typeStringPUBLIC, PASSWORD, or PRIVATE
iconStringURL to group icon
descriptionStringGroup description
ownerStringUID of group owner
membersCountNumberNumber of members
hasJoinedBooleanIf logged-in user is a member
joinedAtNumberWhen user joined (timestamp)
scopeStringUser’s scope (ADMIN, MODERATOR, PARTICIPANT)
createdAtNumberCreation timestamp
tagsArrayGroup tags
metadataObjectCustom data

Next Steps