With increasingly strict rules and regulations on app compliance, content supervision has become a crucial part of the app lifecycle. To meet this need, Agora Chat provides the global-mute feature, which enables you to mute any user ID in one-to-one chats, group chats, or chat rooms, preventing these users from sending messages to other chat users, chat groups, or chat rooms. When global-mute expires, the chat server automatically unmutes the user ID, and this user resumes the privilege of sending messages.
This feature can be widely applied in apps that power real-time engagements. For example, if a user frequently sends illegitimate advertisements to multiple chat rooms, you can use global-mute to prevent this user from sending chat room messages for 15 days; if a user makes improper statements concerning politics, global-mute can permanently prevent this user from sending any messages in one-to-one chats, chat groups, or chat rooms.
Before calling the following methods, make sure you understand the call frequency limit of the Chat RESTful APIs as described in Limitations.
The following table lists common request and response parameters of the Agora Chat RESTful APIs:
Parameter | Type | Description | Required |
---|---|---|---|
host |
String | The domain name assigned by the Agora Chat service to access RESTful APIs. For how to get the domain name, see Get the information of your project. | Yes |
org_name |
String | The unique identifier assigned to each company (organization) by the Agora Chat service. For how to get the org name, see Get the information of the Agora Chat project. | Yes |
app_name |
String | The unique identifier assigned to each app by the Agora Chat service. For how to get the app name, see Get the information of the Agora Chat project. | Yes |
username |
String | The unique login account of the user. The username must be 64 characters or less and cannot be empty. The following character sets are supported:
|
Yes |
Parameter | Type | Description |
---|---|---|
action |
String | The request method. |
organization |
String | The unique identifier assigned to each company (organization) by the Agora Chat service. This is the same as org_name . |
application |
String | A unique internal ID assigned to each app by the Agora Chat service. You can safely ignore this parameter. |
applicationName |
String | The unique identifier assigned to each app by the Agora Chat service . This is the same as app_name . |
uri |
String | The request URI. |
path |
String | The request path, which is part of the request URL. You can safely ignore this parameter. |
data |
JSON | The response data. |
timestamp |
Number | The Unix timestamp (ms) of the HTTP response. |
duration |
Number | The duration (ms) from when the HTTP request is sent to the time the response is received. |
Agora Chat RESTful APIs require Bearer HTTP authentication. Every time an HTTP request is sent, the following Authorization field must be filled in the request header:
Authorization: Bearer ${YourAppToken}
In order to improve project security, Agora uses a token (dynamic key) to authenticate users before they log in to the chat system. Agora Chat RESTful APIs only support authenticating users using app tokens. For details, see Authentication using App Token.
This method mutes a specified user in one-to-one chats, chat groups, or chat rooms. After a successful method call, this user can no longer send messages in one-to-one chats, chat groups, or chat rooms, depending on your settings in the request parameter.
For each App Key, the call frequency limit of this method is 100 per second.
POST https://{host}/{orgName}/{appName}/mutes
For parameters and the detailed descriptions, see Commom parameters.
Parameter | Type | Required | Description |
---|---|---|---|
username |
String | Yes | The user ID that you want to globally mute. |
chat |
Number | No | The amount of time to mute this user ID in one-to-one chats, in seconds. The maximum value is 2,147,483,647.
|
groupchat |
Number | No | The amount of time to mute this user in group chats, in seconds. The maximum value is 2,147,483,647.
|
chatroom |
Number | No | The amount of time to mute this user in chat rooms, in seconds. The maximum value is 2,147,483,647.
|
Parameter | Type | Description |
---|---|---|
Content-Type |
String | The content type. Set is as application/json . |
Authorization |
String | The authentication token of the user or admin, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
result |
String | The result of this method call. ok means that global-mute is successfully enabled. |
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.
curl -L -X POST 'https://XXXX/XXXX/XXXX/mutes' \
-H 'Authorization: Bearer {YourAppToken}' \
-H 'Content-Type: application/json' \
--data-raw '{
"username": "XXXX",
"chat": 100,
"groupchat": 100,
"chatroom": 100
}'
{
"path": "/mutes",
"uri": "https://XXXX/XXXX/XXXX/mutes",
"timestamp": 1631609754727,
"organization": "XXXX",
"application": "XXXX",
"action": "post",
"data": {
"result": "ok"
},
"duration": 74,
"applicationName": "XXXX"
}
This method queries the detailed information of the global-mute settings of the specified user in one-to-one chats, group chats, or chatrooms.
For each App Key, the call frequency limit of this method is 100 per second.
GET https://{host}/{orgName}/{appName}/mutes/{username}
Parameter | Type | Required | Description |
---|---|---|---|
username |
String | Yes | The user ID whose global-mute settings you want to query. |
For other parameters and the detailed descriptions, see Commom parameters.
Parameter | Type | Description |
---|---|---|
Content-Type |
String | The content type. Set is as application/json . |
Authorization |
String | The authentication token of the user or admin, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
userid |
String | The user ID whose global-mute settings you want to query. |
chat |
Number | The remaining time that this user is muted in one-to-one chats, in seconds. The maximum value is 2,147,483,647.
|
groupchat |
Number | The remaining time that this user is muted in group chats, in seconds. The maximum value is 2,147,483,647.
|
chatroom |
Number | The remaining time that this user is muted in group rooms, in seconds. The maximum value is 2,147,483,647.
|
unixtime |
Number | The Unix timestamp of the current operation. |
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.
curl -L -X GET 'https://XXXX/XXXX/XXXX/mutes/{username}' \
-H 'Authorization: Bearer {YourAppToken}' \
-H 'Content-Type: application/json'
{
"path": "/mutes",
"uri": "https://XXXX/XXXX/XXXX/mutes",
"timestamp": 1631609831800,
"organization": "XXXX",
"application": "XXXX",
"action": "get",
"data": {
"userid": "XXXX",
"chat": 96,
"groupchat": 96,
"chatroom": 96,
"unixtime": 1631609831
},
"duration": 13,
"applicationName": "XXXX"
}
This method retrieves all the users that have been globally muted in the app, and returns the remaining time that each user is muted for each type of chat.
For each App Key, the call frequency limit of this method is 100 per second.
GET https://{host}/{orgName}/{appName}/mutes
For parameters and the detailed descriptions, see Commom parameters.
Parameter | Type | Description |
---|---|---|
Content-Type |
String | The content type. Set is as application/json . |
Authorization |
String | The authentication token of the user or admin, in the format of Bearer ${YourAppToken} , where Bearer is a fixed character, followed by an English space, and then the obtained token value. |
Parameter | Type | Required | Description |
---|---|---|---|
pageNum |
Number | Yes | The number of pages for querying the globally muted users in the app. |
pageSize |
Number | Yes | The number of data entries on each page. |
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
username |
String | The user ID whose global-mute settings you want to query. |
chat |
Number | The remaining time that this user is muted in one-to-one chats, in seconds. The maximum value is 2,147,483,647.
|
groupchat |
Number | The remaining time that this user is muted in group chats, in seconds. The maximum value is 2,147,483,647.
|
chatroom |
Number | The remaining time that this user is muted in group rooms, in seconds. The maximum value is 2,147,483,647.
|
unixtime |
Number | The Unix timestamp of the current operation. |
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.
curl -L -X GET 'https://XXXX/XXXX/XXXX/mutes?pageNum=1&pageSize=10' \
-H 'Authorization: Bearer {YourAppToken}' \
-H 'Content-Type: application/json'
{
"path": "/mutes",
"uri": "https://XXXX/XXXX/XXXX/mutes",
"timestamp": 1631609858771,
"organization": "XXXX",
"application": "XXXX",
"action": "get",
"data": {
"data": [
{
"username": "XXXX",
"chatroom": 0
},
{
"username": "XXXX",
"groupchat": 69
},
{
"username": "XXXX",
"chat": 69
},
{
"username": "XXXX",
"chatroom": 69
},
{
"username": "XXXX",
"chatroom": 0
},
{
"username": "XXXX",
"groupchat": 0
},
{
"username": "XXXX",
"chat": 0
}
],
"unixtime": 1631609858
},
"duration": 17,
"applicationName": "XXXX"
}
For details, see HTTP Status Codes.