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 Agora Chat SDK provides the ChatManager
and ChatRoom
classes for chat room management, which allow you to implement the following features:
- Retrieve or modify basic attributes of a chat room
- Retrieve custom attributes of a chat room
- Set custom attributes of a chat room
- Remove 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.
Manage basic chat room attributes
Retrieve basic chat room attributes
All the chat room members can call fetchChatRoomFromServer
to retrieve the detailed information of the current chat room, including the subject, announcement, description, member type, and admin list.
Change chat room name or description
Only the chat room owner and admin can set and update the chat room name and description.
Retrieve or change the chat room announcement
All the 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 chat room members receive the onAnnouncementChanged
callback.
Manage custom chat room attributes
Set a custom attribute
Chat room members can call asyncSetChatroomAttributes
to set one single custom or update an existing attribute set by themselves. After you successfully call this method, other members in the chat room receive an onAttributesUpdate
callback.
If you want to update a custom attribute that is set by other members, call asyncSetChatroomAttributesForced
instead. After you successfully call this method, other members in the chat room receive an onAttributesUpdate
callback.
Set multiple custom attributes
Chat room members can call the asyncSetChatroomAttributes
method to add new custom attributes or update existing attributes set by themselves. After you successfully call this method, other members in the chat room receive an onAttributesUpdate
callback.
If you want to update custom attributes that set by other members, call asyncSetChatroomAttributesForced
instead. After you successfully call this method, other members in the chat room receive an onAttributesUpdate
callback.
Retrieve specified or all custom attributes
All chat room members can call asyncFetchChatroomAttributesFromServer
or asyncFetchChatRoomAllAttributesFromServer
to retrieve specified or all custom attributes of the chat room.
Remove a custom attribute
Chat room members can call asyncRemoveChatRoomAttributeFromServer
to remove one single custom attribute that is set by themselves. After you successfully call this method, other members in the chat room receive an onAttributesRemoved
callback.
If you want to update a custom attribute set by another member, call asyncRemoveChatRoomAttributeFromServerForced
instead. After you successfully call this method, other members in the chat room receive an onAttributesRemoved
callback.
Remove multiple custom attributes
To remove multiple custom attributes, chat room members can call the asyncRemoveChatRoomAttributesFromServer
method with same name to remove multiple custom attributes that are set by themselves. After you successfully call this method, other members in the chat room receive an onAttributesRemoved
callback.
If you want to update custom attributes that set by other members, call asyncRemoveChatRoomAttributesFromServerForced
instead. After you successfully call this method, other members in the chat room receive an onAttributesRemoved
callback.