# User attributes (/en/realtime-media/im/build/build-core-messaging/user-attributes/unity)

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

After joining a Chat channel, a user can update information such as the nickname, avatar, age, and mobile phone number as needed. These are known as user attributes.

    This page shows how to use the Chat SDK to implement managing user attributes.

    <CalloutContainer type="info">
      <CalloutDescription>
        User attributes are stored on the Chat server. If you have security concerns, Agora recommends that you manage user attributes yourself.To ensure information security, app users can only modify their own user attributes. Only app admins can modify the user attributes of other users.
      </CalloutDescription>
    </CalloutContainer>

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

    The Chat SDK uses `IUserInfoManager` to retrieve, set, and modify user attributes. The following are the core methods:

    * `UpdateOwnInfo`: Set and update user attributes.
    * `FetchUserInfoByUserId`: Retrieve the user attributes of the specified user.

    ## Prerequisites [#prerequisites-5]

    Before proceeding, ensure that you meet the following requirements:

    * You have integrated the Chat SDK, initialized the SDK and implemented the functionality of registering accounts and login. For details, see [Chat SDK quickstart](../../get-started-sdk).
    * Have a thorough understanding of the API call frequency limit, the maximum size of all the attributes of a specified user, and the maximum size of all user attributes in an app. For details, see [Known limitations](../limitations).

    ## Implementation [#implementation-5]

    This section shows how to manage user attributes and contacts with the methods provided by the Chat SDK.

    ### Set user attributes [#set-user-attributes-5]

    Chat users can set and update their own attributes. Refer to the code example to set user attributes:

    ```csharp
    // Set the user attributes of the specified user.
    UserInfo userInfo;
    userInfo.userId = currentId;
    userInfo.nickName = "chatuser";
    userInfo.avatarUrl = "http://www.easemob.com";
    userInfo.birth = "2000.10.10";
    userInfo.signature = "hello world";
    userInfo.phoneNumber = "13333333333";
    userInfo.email = "123456@qq.com";
    userInfo.gender = 1; // 1 indicates that the gender is male. 2 means female.
    SDKClient.Instance.UserInfoManager.UpdateOwnInfo(userInfo, new CallBack(
      onSuccess: () => {
      },
      onError:(code, desc) => {
      }
    ));
    ```

    Keys listed in the following table are used by default when user attributes are set on the client side, including the nickname, avatar URL, contact information, email address, gender, signature, birthday and extension fields. When you call the [RESTful API to set](/en/api-reference/api-ref/im/user-attributes-management#setting-user-attributes) or [delete](/en/api-reference/api-ref/im/user-attributes-management#deleting-user-attributes) these user attributes, you must pass in the following keys to make sure that the client can obtain the settings from the server:

    | Field       | Type   | Description                                                                            |
    | :---------- | :----- | :------------------------------------------------------------------------------------- |
    | `nickname`  | String | The user nickname, which can contain at most 64 characters.                            |
    | `avatarurl` | String | The user avatar URL, which can contain at most 256 characters.                         |
    | `phone`     | String | The user's phone number, which can contain at most 32 characters.                      |
    | `mail`      | String | The user's email address, which can contain at most 64 characters.                     |
    | `gender`    | Number | The user gender: `1`：Male; `2`：Female;(Default) `0`: Unknown;Other values are invalid. |
    | `sign`      | String | The user's signature, which can contain at most 256 characters.                        |
    | `birth`     | String | The user's birthday, which can contain at most 256 characters.                         |
    | `ext`       | String | The extension fields.                                                                  |

    ### Retrieve user attributes [#retrieve-user-attributes-5]

    You can use `FetchUserInfoByUserId` to retrieve the user attributes of the specified users. For each method call, you can retrieve the user attributes of a maximum of 100 users.

    Refer to the following code example:

    ```csharp
    // Retrieve user attributes of one or multiple users.
    List idList = new List();
    idList.Add("username");
    SDKClient.Instance.UserInfoManager.FetchUserInfoByUserId
    SDKClient.Instance.UserInfoManager.FetchUserInfoByUserId(idList, type, startId, loadCount, new ValueCallBack>(
      // `result` is in the format of Dictionary
      onSuccess: (result) => {
      // Traverse all the user attributes in the dictionary
      },
      onError:(code, desc) => {
      }
    ));
    ```

    ## Next steps [#next-steps-5]

    This section introduces extra functions you can implement in your app using user attributes and contact management.

    ### Manage user avatar [#manage-user-avatar-5]

    The Chat SDK only supports storing the URL address of the avatar file rather than the file itself. To manage user avatars, you need to use a third-party file storage service.

    To implement user avatar management in your app, take the following steps:

    1. Upload the avatar file to the third-party file storage service. Once the file is successfully uploaded, you get a URL address of the avatar file.
    2. Set the `avatarUrl` parameter in user attributes as the URL address of the avatar file.
    3. To display the avatar, call `FetchUserInfoByUserId` to retrieve the URL of the avatar file, and then render the image on the local UI.

    ### Create and send a namecard using user attributes [#create-and-send-a-namecard-using-user-attributes-4]

    Namecard messages are custom messages that include the user ID, nickname, avatar, email address, and phone number of the specified user. To create and send a namecard, take the following steps:

    1. Create a custom message and set the `event` of the custom message as `userCard`.
    2. Add `userID`, `nickname`, and `avatarUrl` as fileds in `ext`. Send the custom message.

    The following is sample code for creating and sending a namecard message:

    ```csharp
    string event = "userCard";
    Dictionary adict = new Dictionary();
    adict.Add("userId", userInfo.userId);
    adict.Add("nickname", userInfo. nickname);
    adict.Add("avatarUrl", userInfo.avatarUrl);
    // You can add more fields.

    // Create a custom message.
    Message msg = Message.CreateCustomSendMessage(toChatUsername, event, adict);

    // Send the message.
    SDKClient.Instance.ChatManager.SendMessage(ref msg, new CallBack(
       onSuccess: () => {
          Debug.Log($"{msg.MsgId}Sending success");
       },
       onError: (code, desc) => {
          Debug.Log($"{msg.MsgId}Sending failure，errCode={code}, errDesc={desc}");
       }
    ));
    ```

    
  
      
  
