Chat rooms enable real-time messaging among multiple users.
This page shows how to use the Agora Chat SDK to manage the attributes of a chat room in your app.
The Agora Chat SDK provides the ChatRoom
, ChatRoomManager
, and ChatRoomEventHandler
classes for chat room 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 room features.
All chat room members can call fetchChatRoomAnnouncement
to retrieve the chat room announcements.
The following code sample shows how to retrieve the chat room announcements:
try {
String? announcement =
await ChatClient.getInstance.chatRoomManager.fetchChatRoomAnnouncement(
roomId,
);
} on ChatError catch (e) {
}
Only the chat room owner and admins can call updateChatRoomAnnouncement
to set and update the announcements. The length of the chat room announcements can be a maximum of 512 characters. Once the chat room announcements are updated, all the other chat room members receive the ChatRoomEventHandler#onAnnouncementChangedFromChatRoom
callback.
The following code sample shows how to update the chat room announcements:
try {
await ChatClient.getInstance.chatRoomManager.updateChatRoomAnnouncement(
roomId,
newAnnouncement,
);
} on ChatError catch (e) {
}
The chat room owner and admins can call changeChatRoomName
to set and update the chat room name. The length of a chat room name can be a maximum of 128 characters.
The following code sample shows how to update the chat room name:
try {
await ChatClient.getInstance.chatRoomManager.changeChatRoomName(
roomId,
newName,
);
} on ChatError catch (e) {
}
The chat room owner and admins can call changeChatRoomDescription
to set and update the chat room description. The length of a chat room description can be a maximum of 512 characters.
The following code sample shows how to update the chat room description:
try {
await ChatClient.getInstance.chatRoomManager.changeChatRoomDescription(
roomId,
newDesc,
);
} on ChatError catch (e) {
}
For details, see Chat Room Events.