logo
On this page

Manage group info


ZEGOCLOUD's In-app Chat (the ZIM SDK) provides the capability of group information management, allowing you to get or modify group info, such as group name, nickname in the group, group avatar, group notice, and more.

Warning
  • Before you use this feature, you must join a group first. To join a group, refer to the Chapter Join a group of Manage groups.
  • All in-group members (group owner included) can use this feature.

Get group info

To know the detailed info of the group you joined, call the queryGroupInfo method.

You will receive the group info through the callback ZIMGroupInfoQueriedResult after the query succeeds.

SampleCode
// Get the group info, such as group name, nicknames, group notice, and group avatar URL.
var groupID = '';
zim.queryGroupInfo(groupID)
    .then(function ({ groupInfo }) {
        // Query successful. 
    })
    .catch(function (err) {
        // Query failed. 
    });
1
Copied!

Modify the group name

To modify the group name after joining a group, call the updateGroupName method.

All group members receive a notification through the callback groupNameUpdated after the group name is modified successfully.

SampleCode
// Group members  modify group name
// groupName is a string with a maximum of 64 bytes, with no special character restrictions.
var groupID = '';
var groupName = '';
zim.updateGroupName(groupName, groupID)
    .then(function ({ groupID, groupName }) {
        // Operation successful.
    })
    .catch(function (err) {
        // Operation failed.
    });

// Register and listen for the callback groupNameUpdated
zim.on('groupNameUpdated', function (zim, { groupID, groupName, operatedInfo }) {
    console.log('groupNameUpdated', groupID, groupName, operatedInfo);
});
1
Copied!

Modify the group avatar

After logging in and joining a group, if a user wants to modify the avatar of the group they have joined, they can do so by calling the updateGroupAvatarUrl interface to modify the group avatar.

After a successful modification, all group members will receive a notification through groupAvatarUrlUpdated.

SampleCode
// Group members  modify group avatar
// The URL can be up to 500 bytes with no special character limitations.
var groupID = '';
var groupAvatarUrl = '';
zim.updateGroupAvatarUrl(groupAvatarUrl, groupID)
.then(function ({ groupID, groupAvatarUrl }) {
// Operation successful.
})
.catch(function (err) {
    // Operation failed.
});

// Register and listen for the callback groupAvatarUrlUpdated
zim.on('groupAvatarUrlUpdated', function (zim, { groupID, groupAvatarUrl, operatedInfo }) {
console.log('groupAvatarUrlUpdated', groupID, groupAvatarUrl, operatedInfo);
});
1
Copied!

Modify the group notice

To modify the group notice after joining a group, call the updateGroupNotice method.

All group members receive a notification through the callback groupNoticeUpdated when the group notice is modified successfully.

SampleCode
// Group members Modify the group notice
var groupID = '';
var groupNotice = '';
zim.updateGroupNotice(groupNotice, groupID)
    .then(function ({ groupID, groupNotice }) {
        // Operation successful.
    })
    .catch(function (err) {
        // Operation failed.
    });

// Register and listen for the callback groupNoticeUpdated
zim.on('groupNoticeUpdated', function (zim, { groupID, groupNotice, operatedInfo }) {
    console.log('groupNoticeUpdated', groupID, groupNotice, operatedInfo);
});
1
Copied!

Modify the group alias

Group alias is a personalized nickname set by users for a group chat to distinguish from other group chats. For example, you can set the alias for a work group as "Work Group" and the alias for a family group as "Family Group", which makes it more convenient to identify the group chats.

Note

Group alias is only visible to the user who sets it and does not affect the display of the group name for other group chat members.

After logging in and joining a group, if a user wants to modify the group alias, the user can call the updateGroupAlias interface to modify the group alias. The group alias is only visible to the user themselves, and the alias for the corresponding conversation will be automatically synchronized.

SampleCode
// Modify the group alias
try {
    const groupAlias = "new_group_alias_example"; // groupAlias is a string with a maximum of 256 bytes, with no special character restrictions.

    const groupID = "example_group_id"; 

    // Call the updateGroupAlias method
    const result = await zim.updateGroupAlias(groupAlias, groupID);
    console.log("Update succeeded:", result);
} catch (error) {
    console.error("Update failed:", error);
}
1
Copied!

Previous

Manage groups

Next

Manage group properties