Skip to main content

Manage chat room attributes

Chat room attributes consist of basic attributes (such as room subject, room description, and room announcement) and custom attributes. When basic attributes cannot satisfy the business requirements, users can add custom attributes that are synchronized with all chat room members. Custom attributes can be used to store information such as chat room type, game roles, game status, and host positions. They are stored as key-value maps, and the updates of custom attributes are synchronized with all chat room members.

This page shows how to use the Agora Chat SDK to manage basic and custom attributes of chat rooms in your app.

Understand the tech

The Chat SDK provides the ChatManager and ChatRoom classes for chat room management, which allows you to implement the following features:

  • Set custom attributes of a chat room
  • Remove custom attributes of a chat room
  • Retrieve or modify basic attributes of a chat room
  • Retrieve custom attributes of a chat room

Prerequisites

Before proceeding, ensure that you meet the following requirements:

  • You have initialized the Chat SDK. For details, see SDK quickstart.
  • You understand the call frequency limit of the Chat APIs supported by different pricing plans as described in Limitations.
  • You understand the number of chat rooms supported by different pricing plans as described in Pricing Plan Details.

Implementation

This section introduces how to call the APIs provided by the Chat SDK to implement the features listed above.

Retrieve and modify the chat room attributes

All the chat room members can call fetchChatRoomFromServer to retrieve the detailed information of the current chat room, including the subject, annoucenments, description, member type, and admin list. The chat room owner and admin can also set and update the chat room information.


_8
// The chat room member call fetchChatRoomFromServer to get the information of the specified chat room.
_8
ChatRoom chatRoom = ChatClient.getInstance().chatroomManager().fetchChatRoomFromServer(chatRoomId);
_8
_8
// The chat room owner and admin call changeChatRoomSubject to modify the chat room subject.
_8
ChatRoom chatRoom = ChatClient.getInstance().chatroomManager().changeChatRoomSubject(chatRoomId, newSubject);
_8
_8
// The chat room owner and admin call changeChatroomDescription to modify the chat room description.
_8
ChatRoom chatRoom = ChatClient.getInstance().chatroomManager().changeChatroomDescription(chatRoomId, newDescription);

Manage chat room announcements

All the chat room members can retrieve the chat room announcements. The chat room owner and admin can set and update the announcements. Once the announcements are updated, all the chat room members receive the onAnnouncementChanged callback.


_5
// Chat room members can call fetchChatRoomAnnouncement to retrieve the chat room annoucements.
_5
String announcement = ChatClient.getInstance().chatroomManager().fetchChatRoomAnnouncement(chatRoomId);
_5
_5
// The chat room owner and admin can call updateChatRoomAnnouncement to set or update the chat room announcements.
_5
ChatClient.getInstance().chatroomManager().updateChatRoomAnnouncement(chatRoomId, announcement);

Listen for chat room events

For details, see Chat Room Events.