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 Group
, IGroupManager
, and IGroupManagerDelegate
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:
SDKClient.Instance.GroupManager.ChangeGroupName(groupId, groupName, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));
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:
SDKClient.Instance.GroupManager.ChangeGroupDescription(groupId, description, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));
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 IGroupManagerDelegate#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:
SDKClient.Instance.GroupManager.UpdateGroupAnnouncement(groupId, announcement, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));
All chat group members can call GetGroupAnnouncementFromServer
to retrieve the chat group announcements from the server.
The following code sample shows how to retrieve the chat group announcements:
SDKClient.Instance.GroupManager.GetGroupAnnouncementFromServer(currentGroupId, new ValueCallBack<string>(
onSuccess: (str) =>
{
},
onError: (code, desc) =>
{
}
));
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 IGroupManagerDelegate#OnSharedFileAddedFromGroup
callback.
The following code sample shows how to upload chat group shared files:
SDKClient.Instance.GroupManager.UploadGroupSharedFile(groupId, filePath, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));
All chat group members can call DeleteGroupSharedFile
to delete shared files in a chat group. Once a shared file is deleted, all the other chat group members receive the IGroupManagerDelegate#OnSharedFileAddedFromGroup#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:
SDKClient.Instance.GroupManager.DeleteGroupSharedFile(groupId, id, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));
All chat group members can call GetGroupFileListFromServer
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:
SDKClient.Instance.GroupManager.GetGroupFileListFromServer(groupId, pageNum, pageSize, handle: new ValueCallBack<List<GroupSharedFile>> (
onSuccess: (fileList) =>
{
},
onError: (code, desc) =>
{
}
));
Only the chat group owner and admins can call UpdateGroupExt
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:
SDKClient.Instance.GroupManager.UpdateGroupExt(currentGroupId, extension, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));
For details, see Chat Group Events.