Chat groups enable real-time messaging among multiple users.
This page shows how to use the Agora Chat SDK to manage the attributes of a chat group in your app.
The Agora Chat SDK provides the ChatGroup
, ChatGroupManager
, and ChatGroupEventHandler
classes for chat group management, which allows you to implement the following features:
Before proceeding, ensure that you meet the following requirements:
This section describes how to call the APIs provided by the Agora Chat SDK to implement chat group features.
The chat group owner and admins can call changeGroupName
to set and update the chat group name. The maximum length of a chat group name is 128 characters.
The following code sample shows how to update the chat group name:
try {
await ChatClient.getInstance.groupManager.changeGroupName(
groupId,
newName,
);
} on ChatError catch (e) {
}
The chat group owner and admins can call changeGroupDescription
to set and update the chat group description. The maximum length of a chat group description is 512 characters.
The following code sample shows how to update the chat group description:
try {
await ChatClient.getInstance.groupManager.changeGroupDescription(
groupId,
newDesc,
);
} on ChatError catch (e) {
}
Only the chat group owner and admins can call updateGroupAnnouncement
to set and update the announcements. Once the chat group announcements are updated, all the other chat group members receive the ChatGroupEventHandler#onAnnouncementChangedFromGroup
callback. The maximum total length of chat group announcements is 512 characters.
The following code sample shows how to update the chat group announcements:
try {
await ChatClient.getInstance.groupManager.updateGroupAnnouncement(
groupId,
newAnnouncement,
);
} on ChatError catch (e) {
}
All chat group members can call fetchAnnouncementFromServer
to retrieve the chat group announcements from the server.
The following code sample shows how to retrieve the chat group announcements:
try {
String? announcement =
await ChatClient.getInstance.groupManager.fetchAnnouncementFromServer(
groupId,
);
} on ChatError catch (e) {
}
All chat group members can call uploadGroupSharedFile
to upload shared files to a chat group. The maximum file size is 10 MB. Once a shared file is uploaded, all the other chat group members receive the ChatGroupEventHandler#onSharedFileAddedFromGroup
callback.
The following code sample shows how to upload chat group shared files:
try {
await ChatClient.getInstance.groupManager.uploadGroupSharedFile(
groupId,
filePath,
);
} on ChatError catch (e) {
}
All chat group members can call removeGroupSharedFile
to delete shared files in a chat group. Once a shared file is deleted, all the other chat group members receive the ChatGroupEventHandler#onSharedFileDeletedFromGroup
callback. The chat group owner and chat group admins can delete all of the shared files, whereas chat group members can only delete the shared files that they have personally uploaded.
The following code sample shows how to delete chat group shared files:
try {
await ChatClient.getInstance.groupManager.removeGroupSharedFile(
groupId,
fileId,
);
} on ChatError catch (e) {
}
All chat group members can call fetchGroupFileListFromServer
to retrieve the list of shared files in a chat group from the server.
The following code sample shows how to retrieve the list of shared files in a chat group:
try {
List<ChatGroupSharedFile> list =
await ChatClient.getInstance.groupManager.fetchGroupFileListFromServer(
groupId,
pageNum: pageNum,
pageSize: pageSize,
);
} on ChatError catch (e) {
}
Only the chat group owner and admins can call updateGroupExtension
to update the extension fields of a chat group. The extension fields enable users to perform customized operations on a chat group. The maximum length of each extension field is 8 KB, and it must be in the JSON format.
The following code sample shows how to update the chat group extension fields:
try {
await ChatClient.getInstance.groupManager.updateGroupExtension(
groupId,
extension,
);
} on ChatError catch (e) {
}
For details, see Chat Group Events.