Manage chat room mute list

Updated

Shows how to perform chat room member mute management by calling the Agora Chat RESTful APIs.

This page shows how to perform chat room member mute management by calling the Chat RESTful APIs, including muting and unmuting members in a chat room, and retrieving the list of muted members.

Before calling the following methods, ensure that you understand the call frequency limit of the Chat RESTful APIs described in Limitations.

Common parameters

The following table lists common request and response parameters of the Chat RESTful APIs:

Request parameters

ParameterTypeDescriptionRequired
hostStringThe domain name assigned by the Chat service to access RESTful APIs. For how to get the domain name, see Get the information of your project.Yes
app_idStringThe unique identifier automatically assigned to each project by AgoraYes
usernameString

The unique login account of the user. The user ID must be 64 characters or less and cannot be empty. The following character sets are supported:

  • 26 lowercase English letters (a-z)
  • 10 numbers (0-9)
  • "_", "-", "."

Do not use any of the 26 uppercase English letters (A-Z). Ensure that each username under the same App ID is unique.

Yes
chatroom_idStringThe chat room ID. The unique chat room identifier assigned to each chat room by the Chat. You can get the chat room ID from the response body in Retrieve the basic information of all chat rooms.Yes

Response parameters

ParameterTypeDescription
actionStringThe request method.
organizationStringThe unique identifier assigned to each company (organization) by the Chat service.
applicationStringA unique internal ID assigned to each app by the Chat service. You can safely ignore this parameter.
applicationNameStringThe unique identifier assigned to each app by the Chat service .
uriStringThe request URI.
entities JSONThe response entity.
dataJSONThe details of the response.
timestampNumberThe Unix timestamp (ms) when the user is registered.
durationNumberThe time duration (ms) from sending the HTTP request to receiving the response.

Muting a chat room member

Mutes a chat room member. Once a chat room member is muted, this member cannot send messages in the chat room.

For each App Key, the call frequency limit of this method is 100 per second.

HTTP request

POST https://{host}/app-id/{app_id}/chatrooms/{chatroom_id}/mute

Path parameter

For the parameters and detailed descriptions, see Common parameters .

Request header

ParameterTypeDescriptionRequired
Content-TypeStringapplication/jsonYes
AcceptStringapplication/jsonYes
AuthorizationStringThe authentication token of the user or administrator, in the format of Bearer ${token}, where Bearer is a fixed character, followed by an English space, and then the obtained token value.Yes

Request body

The request body is a JSON object, which contains the following fields:

FieldTypeDescriptionRequired
mute_durationNumberThe length of time to mute speech from the current time. The unit is milliseconds.-1 indicates that the member is muted permanently.Yes
usernamesStringThe array of user IDs of chat room members that are to be muted. You can pass in a maximum of 60 user IDs.Yes

HTTP response

Response body

If the returned HTTP status code is 200, the request succeeds, and the response body contains the following fields:

FieldTypeDescription
resultBoolThe mute result: true: Success. false: Failure.
expireNumberThe Unix timestamp (ms) when the mute state expires.
userArrayThe username of the muted member.

For other fields and detailed descriptions, see Common parameters.

If the returned HTTP status code is not 200, the request fails. You can refer to Status codes for possible reasons.

Example

Request example

# Replace  with the app token generated in your server.
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer ' -d
'{
    "usernames": [
        "user1",
        "user2"
    ],
    "mute_duration": 86400000
}''http://a1.easemob.com/easemob-demo/testapp/chatrooms/1265710621211/mute'

Response example

{
    "action": "post",
    "application": "22bcffa0-XXXX-XXXX-9df8-516f6df68c6d",
    "applicationName": "XXXX",
    "data": [
        {
            "result": true,
            "expire": 1642148173726,
            "user": "user1"
        },
        {
            "result": true,
            "expire": 1642148173726,
            "user": "user2"
        }
    ],
    "duration": 0,
    "entities": [],
    "organization": "XXXX",
    "timestamp": 1642060750410,
    "uri": "http://XXXX/app-id/XXXX/chatrooms/XXXX/mute"
}

Unmuting members

Unmutes one or more chat room members. The unmuted members can continue to send messages in the chat room.

For each App Key, the call frequency limit of this method is 100 per second.

HTTP request

DELETE https://{host}/app-id/{app_id}/chatrooms/{chatroom_id}/mute/{member}

Path parameter

ParameterTypeDescriptionRequired
memberStringThe username of the chat room member to be unmuted. You can pass in a maximum of 60 user IDs that are separated with commas (","). In the URL, use "%2C" to represent ",".Yes

For other parameters and detailed descriptions, see Common parameters.

Request header

ParameterTypeDescriptionRequired
AcceptStringapplication/jsonYes
AuthorizationStringThe authentication token of the user or administrator, in the format of Bearer ${token}, where Bearer is a fixed character, followed by an English space, and then the obtained token value.Yes

HTTP response

Response body

If the returned HTTP status code is 200, the request succeeds. The response body contains the following fields:

FieldTypeDescription
resultBoolThe unmute result: true: Success. false: Failure.
userStringThe username of the unmuted member.

For other fields and detailed descriptions, see Common parameters.

If the returned HTTP status code is not 200, the request fails. You can refer to Status codes for possible reasons.

Example

Request example

# Replace  with the app token generated in your server.
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer ' 'https://XXXX/app-id/XXXX/chatrooms/XXXX/mute/XXXX'

Response example

{
    "action": "delete",
    "application": "527cd7e0-XXXX-XXXX-9f59-ef10ecd81ff0",
    "uri": "http://XXXX/app-id/XXXX/chatrooms/XXXX/mute/XXXX",
    "entities": [],
    "data": [
        {
            "result": true,
            "user": "XXXX"
        }
    ],
    "timestamp": 1489072695859,
    "duration": 0,
    "organization": "XXXX",
    "applicationName": "XXXX"
}

Retrieving muted members

Retrieves the list of all the muted members in the specified chat room.

For each App Key, the call frequency limit of this method is 100 per second.

GET https://{host}/app-id/{app_id}/chatrooms/{chatroom_id}/mute

HTTP request

Path parameter

For the parameters and detailed descriptions, see Common parameters .

Request header

ParameterTypeDescriptionRequired
AcceptStringapplication/jsonYes
AuthorizationStringThe authentication token of the user or administrator, in the format of Bearer ${token}, where Bearer is a fixed character, followed by an English space, and then the obtained token value.Yes

HTTP response

Response body

If the returned HTTP status code is 200, the request succeeds. The response body contains the following fields:

FieldTypeDescription
expireNumberThe Unix timestamp (ms) when the mute expires.
userStringThe username of the muted member.

For other fields and detailed descriptions, see Common parameters.

If the returned HTTP status code is not 200, the request fails. You can refer to Status codes for possible reasons.

Example

Request example

# Replace  with the app token generated in your server.
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer ' 'https://XXXX/app-id/XXXX/chatrooms/XXXX/mute'

Response example

{
    "action": "post",
    "application": "527cd7e0-XXXX-XXXX-9f59-ef10ecd81ff0",
    "uri": "http://XXXX/app-id/XXXX/chatrooms/XXXX/mute",
    "entities": [],
    "data": [
        {
            "expire": 1489158589481,
            "user": "user1"
        },
        {
            "expire": 1489158589481,
            "user": "user2"
        }
    ],
    "timestamp": 1489072802179,
    "duration": 0,
    "organization": "XXXX",
    "applicationName": "XXXX"
}

Muting all chat room members

Mutes all chat room members. Once this method call succeeds, only the members on the chat room allow list can send messages. For details, see Manage Chat Room Allow List.

Muting all chat room members has no connection with the mute list. That is to say, calling this API will not add all chat room members to the chat room mute list.

For each App Key, the call frequency limit of this method is 100 per second.

HTTP request

POST https://{host}/app-id/{app_id}/chatrooms/{chatroom_id}/ban

Path parameter

For the parameters and detailed descriptions, see Common parameters.

Request header

ParameterTypeRequiredDescription
Content-TypeStringYesapplication/json
AuthorizationStringYesThe authentication token of the user or administrator, in the format of Bearer ${token}, where Bearer is a fixed character, followed by an English space, and then the obtained token value.

HTTP response

Response body

If the returned HTTP status code is 200, the request succeeds. The response body contains the following fields:

ParameterTypeDescription
resultBoolWhether all members are successfully muted: true: Yes. false: No.
expireLongThe Unix timestamp when the global mute state expires. Unit: milliseconds.

For other fields and detailed descriptions, see Common parameters.

If the returned HTTP status code is not 200, the request fails. You can refer to Status codes for possible reasons.

Example

Request example

curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://XXXX/app-id/XXXX/chatrooms/1265710621211/ban'

Response example

{
  "action": "put",
  "application": "5cf28979-XXXX-XXXX-b969-60141fb9c75d",
  "uri": "http://XXXX/app-id/XXXX/chatrooms/XXXX/ban",
  "entities": [],
  "data": {
    "mute": true
  },
  "timestamp": 1594628861058,
  "duration": 1,
  "organization": "XXXX",
  "applicationName": "XXXX"
} 

Unmuting all chat room members

Unmutes all chat room members. Once unmuted, the chat room members resume the right to send messages in the chat room.

For each App Key, the call frequency limit of this method is 100 per second.

HTTP request

DELETE https://{host}/app-id/{app_id}/chatrooms/{chatroom_id}/ban

Path parameter

For the parameters and detailed descriptions, see Common parameters.

Request header

ParameterTypeRequiredDescription
Content-TypeStringYesapplication/json
AuthorizationStringYesThe authentication token of the user or administrator, in the format of Bearer ${token}, where Bearer is a fixed character, followed by an English space, and then the obtained token value.

HTTP response

Response body

If the returned HTTP status code is 200, the request succeeds. The response body contains the following fields:

ParameterTypeDescription
resultBooleanWhether all chat room members are successfully unmuted: true: Yes. false: No.

For other fields and detailed descriptions, see Common parameters.

If the returned HTTP status code is not 200, the request fails. You can refer to Status codes for possible reasons.

Example

Request example

curl -X DELETE -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://XXXX/app-id/XXXX/chatrooms/XXXX/ban'

Response example

{
  "action": "put",
  "application": "5cf28979-XXXX-XXXX-b969-60141fb9c75d",
  "uri": "http://XXXX/app-id/XXXX/chatrooms/XXXX/ban",
  "entities": [],
  "data": {
    "mute": false
  },
  "timestamp": 1594628899502,
  "duration": 1,
  "organization": "XXXX",
  "applicationName": "XXXX"
}

Status codes

For details, see HTTP Status Codes.