# Manage chat room attributes (/en/realtime-media/im/build/build-groups-rooms-and-threads/chat-room/manage-chatroom-attributes/flutter)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

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 a chat room in your app.

    ## Understand the tech [#understand-the-tech-2]

    The Chat SDK provides the `ChatRoom`, `ChatRoomManager`, and `ChatRoomEventHandler` classes for chat room management, which allow you to implement the following features:

    ## Prerequisites [#prerequisites-2]

    Before proceeding, ensure that you meet the following requirements:

    * You have initialized the Chat SDK. For details, see [SDK quickstart](../../../get-started-sdk).
    * You understand the call frequency limit of the Chat APIs supported by different pricing plans as described in [Limitations](../../limitations).
    * You understand the number of chat rooms supported by different pricing plans as described in [Pricing Plan Details](../../../reference/pricing-plan-details).

    ## Implementation [#implementation-2]

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

    ### Manage basic chat room attributes [#manage-basic-chat-room-attributes-2]

    #### Retrieve basic chat room attributes [#retrieve-basic-chat-room-attributes-2]

    All chat room members can call `fetchChatRoomInfoFromServer` to retrieve the basic attributes of a chat room, including the chat room ID, name, description, announcement, owner, admin list, maximum number of members, and whether all members are muted.

    The following code sample shows how to retrieve basic chat room attributes:

    ```dart
    // Chat room members can call fetchChatRoomInfoFromServer to retrieve the basic attributes of a chat room.
    try {
      ChatRoom room = await ChatClient.getInstance.chatRoomManager.fetchChatRoomInfoFromServer(roomId);
    } on ChatError catch (e) {
    }
    ```

    #### Change the chat room name or description [#change-the-chat-room-name-or-description]

    Only the chat room owner and admin can set and update the chat room name and description.

    ```dart
    // The chat room owner and admin can call changeChatRoomName to change the chat room name.
    try {
      await ChatClient.getInstance.chatRoomManager.changeChatRoomName(
        roomId,
        newName,
      );
    } on ChatError catch (e) {
    }

    // The chat room owner and admin call changeChatRoomDescription to modify the chat room description.
    try {
      await ChatClient.getInstance.chatRoomManager.changeChatRoomDescription(
        roomId,
        newDesc,
      );
    } on ChatError catch (e) {
    }
    ```

    #### Retrieve or change chat room announcement [#retrieve-or-change-chat-room-announcement]

    All chat room members can retrieve the chat room announcement.

    Only the chat room owner and admin can set and update the announcement. Once the announcement is updated, all the other chat room members receive the `ChatRoomEventHandler#onAnnouncementChangedFromChatRoom` callback.

    ```dart
    // Chat room members can call fetchChatRoomAnnouncement to retrieve the chat room announcement.
    try {
      String? announcement =
          await ChatClient.getInstance.chatRoomManager.fetchChatRoomAnnouncement(
        roomId,
      );
    } on ChatError catch (e) {
    }
    // The chat room owner and admin can call updateChatRoomAnnouncement to set or update the chat room announcement.
    try {
      await ChatClient.getInstance.chatRoomManager.updateChatRoomAnnouncement(
        roomId,
        newAnnouncement,
      );
    } on ChatError catch (e) {
    }
    ```

    ### Manage custom chat room attributes [#manage-custom-chat-room-attributes-2]

    #### Set one ore more custom attributes [#set-one-ore-more-custom-attributes]

    Chat room members can call `addAttributes` to set one or more custom attributes. Use this method to add new custom attributes or update existing attributes that are set by yourself and others. After you successfully call this method, other members in the chat room receive an `EMChatRoomEventHandler#onAttributesUpdated` callback.

    ```dart
    // Sets custom attributes by specifying the chat room ID and key-value maps of the attributes.
    try {
      Map? failInfo =
          await ChatClient.getInstance.chatRoomManager.addAttributes(
        "room",
        attributes: kv,
        deleteWhenLeft: true,
        overwrite: true,
      );
    } on ChatError catch (e) {}
    ```

    #### Retrieve specified or all custom attributes [#retrieve-specified-or-all-custom-attributes-2]

    All chat room members can call `fetchChatRoomAttributes` to retrieve the specified or all custom attributes of the chat room.

    ```dart
    // Retrieves certain or all custom attributes by specifying chat room ID and attribute keys.
    try {
        Map? attributes =
            await ChatClient.getInstance.chatRoomManager.fetchChatRoomAttributes(
            roomId,
            keys,
        );
    } on ChatError catch (e) {}
    ```

    #### Remove one or more custom attributes [#remove-one-or-more-custom-attributes]

    Chat room members can call `removeAttributes` to remove one or more custom attributes that are set by themselves and others. After you successfully call this method, other members in the chat room receive an `EMChatRoomEventHandler#onAttributesRemoved` callback.

    ```dart
    // Removes custom attributes by specifying the chat room ID and the attribute key list.
    try {
      Map? failInfo =
          await ChatClient.getInstance.chatRoomManager.removeAttributes(
        roomId,
        keys: keys,
        force: true,
      );
    } on ChatError catch (e) {}
    ```

    ### Listen for chat room events [#listen-for-chat-room-events]

    For details, see [Chat Room Events](manage-chatrooms#listen-for-chat-room-events).

    
  
      
  
      
  
      
  
      
  
