Skip to main content

Manage chat group announcement and files

This page shows how to manage the group announcement and group files by calling Chat RESTful APIs. Before calling the following methods, ensure that you understand the call frequency limit 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
org_nameStringThe unique identifier assigned to each company (organization) by the Chat service. For how to get the org name, see Get the information of your project.Yes
app_nameStringThe unique identifier assigned to each app by the Chat service. For how to get the app name, see Get the information of your project.Yes
usernameStringThe 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)
  • 26 uppercase English letters (A-Z)
  • 10 numbers (0-9)
  • "_", "-", "."
  • The username is case insensitive, so Aa and aa are the same username.
  • Ensure that each username under the same app is unique.
Yes

Response parameters

ParameterTypeDescription
actionStringThe request method.
organizationStringThe unique identifier assigned to each company (organization) by the Chat service. This is the same as org_name.
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. This is the same as app_name.
uriStringThe request URI.
pathStringThe request path, which is part of the request URI. You can safely ignore this parameter.
entities JSONThe response entity.
dataJSONThe details of the response.
timestampNumberThe Unix timestamp (ms) of the HTTP response.
durationNumberThe duration (ms) from when the HTTP request is sent to the time the response is received.

Authorization

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:


_1
Authorization: Bearer ${YourAppToken}

In order to improve the security of the project, Agora uses a token (dynamic key) to authenticate users before they log in to the chat system. Chat RESTful APIs only support authenticating users using app tokens. For details, see Authentication using App Token.

Retrieving the chat group announcement

Retrieves the announcement of the specified chat group.

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

HTTP request


_1
GET https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/announcement

Path parameter

ParameterTypeDescriptionRequired
group_idStringThe group ID.Yes

For other parameters and detailed descriptions, see Common parameters.

Request header

ParameterTypeDescriptionRequired
Content-TypeStringThe parameter type. Set it as application/json.Yes
AcceptStringThe parameter type. Set it as application/json.Yes
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, and the data field in the response body contains the following parameters.

ParameterTypeDescription
announcementStringThe content of the group announcement.

For other fields and descriptions, see Public parameter.

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

Example

Request example


_1
curl -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/chatgroups/66021836783617/announcement'

Response example


_13
{
_13
"action": "get",
_13
"application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
_13
"uri": "http://XXXX/XXXX/XXXX/chatgroups/66021836783617/announcement",
_13
"entities": [],
_13
"data": {
_13
"announcement" : "group announcement..."
_13
},
_13
"timestamp": 1542363546590,
_13
"duration": 0,
_13
"organization": "XXXX",
_13
"applicationName": "XXXX"
_13
}

Modifying the chat group announcement

Modifies the announcement of the specified chat group. The group announcement cannot exceed 512 characters.

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

HTTP request


_1
POST https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/announcement

Path parameter

ParameterTypeDescriptionRequired
group_idStringThe group ID.Yes

For other parameters and detailed descriptions, see Common parameters.

Request header

ParameterTypeDescriptionRequired
Content-TypeStringThe parameter type. Set it as application/json.Yes
AcceptStringThe parameter type. Set it as application/json.Yes
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, and the data field in the response body contains the following parameters.

ParameterTypeDescription
idStringThe group ID.
resultBooleanWhether the group announce is successfully modified.
  • true: Yes.
  • false: No.

For other fields and descriptions, see Public parameter.

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

Example

Request example


_1
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' -d '{"announcement" : "group announcement…"}' 'http://XXXX/XXXX/XXXX/chatgroups/66021836783617/announcement'

Response example


_14
{
_14
"action": "post",
_14
"application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
_14
"uri": "http://XXXX/XXXX/XXXX/chatgroups/66021836783617/announcement",
_14
"entities": [],
_14
"data": {
_14
"id" : "66021836783617",
_14
"result" : true
_14
},
_14
"timestamp": 1542363546590,
_14
"duration": 0,
_14
"organization": "XXXX",
_14
"applicationName": "XXXX"
_14
}

Retrieving the chat group shared files

Retrieves the shared files of the specified chat group with pagination. Each page can have a maximum of 1000 shared files.

After successfully calling this method, you can get the file_id from the response, which is the unique file ID that identifies the shared file. This field can be used to specify a shared file when you download or remove it.

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

HTTP request


_4
GET https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/share_files
_4
_4
// Gets a group's shared files with pagination.
_4
GET https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/share_files?pagenum=1&pagesize=10

Path parameter

ParameterTypeDescriptionRequired
group_idStringThe group ID.Yes

For the descriptions of other path parameters, see Common Parameters.

Request header

ParameterTypeDescriptionRequired
Content-TypeStringThe parameter type. Set it as application/json.Yes
AcceptStringThe parameter type. Set it as application/json.Yes
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, and the data field in the response body contains the following parameters.

ParameterTypeDescription
file_idStringThe ID of the chat group shared file. This field is required if you want to download or remove a group's shared files.
file_nameStringThe name of the chat group shared file.
file_ownerStringThe ID of the user uploading the shared file.
file_sizeNumberThe size of the chat group shared file, in bytes.
createdLongThe Unix timestamp for uploading the group shared file.

For other fields and descriptions, see Public parameter.

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

Example

Request example


_1
curl -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/chatgroups/66021836783617/share_files?pagenum=1&pagesize=10'

Response example


_34
{
_34
"action": "get",
_34
"application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
_34
"params": {
_34
"pagesize": [
_34
"10"
_34
],
_34
"pagenum": [
_34
"1"
_34
]
_34
},
_34
"uri": "http://XXXX/XXXX/XXXX/chatgroups/66021836783617/share_files",
_34
"entities": [],
_34
"data": [
_34
{
_34
"file_id": "dbd88d20-XXXX-XXXX-95fc-638fc2d59a8d",
_34
"file_name": "159781149272586.jpg",
_34
"file_owner": "u1",
_34
"file_size": 326127,
_34
"created": 1597811492594
_34
},
_34
{
_34
"file_id": "b30e0be0-XXXX-XXXX-8732-172a3f85134f",
_34
"file_name": "159781141836993.jpg",
_34
"file_owner": "u1",
_34
"file_size": 326127,
_34
"created": 1597811424158
_34
}
_34
],
_34
"timestamp": 1542363546590,
_34
"duration": 0,
_34
"organization": "XXXX",
_34
"applicationName": "XXXX"
_34
}

Uploading a chat group shared file

Uploads a chat group shared file. This shared file cannot exceed 10 MB.

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

HTTP request


_1
POST https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/share_files

Path parameter

ParameterTypeDescriptionRequired
group_idStringThe group ID.Yes

For the descriptions of other path parameters, see Common Parameters.

Request header

ParameterTypeDescriptionRequired
Content-TypeStringThe parameter type. Set it as application/json.Yes
AcceptStringThe parameter type. Set it as application/json.Yes
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
restrict-accessBooleanWhether to restrict the access to the chat group shared file to chat group members only.Yes

HTTP response

Response body

If the returned HTTP status code is 200, the request succeeds, and the data field in the response body contains the following parameters.

ParameterTypeDescription
file_urlStringThe URL to shared files of groups on the Chat server.
group_idStringThe group ID.
file_nameStringThe name of the group's shared file.
createdLongThe upload time of the group's shared file.
file_idStringThe ID of the group's shared file. This field is required if you want to download or remove a group's shared files.
file_sizeNumberThe size of the group's shared file, in the unit of bytes.

For other fields and descriptions, see Public parameter.

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

Example

Request example


_1
curl -X POST 'http://XXXX/XXXX/XXXX/chatgroups/66021836783617/share_files' -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' -H 'restrict-access: true' -F file=@/Users/test/image/IMG_3.JPG

Response example


_18
{
_18
"action" : "post",
_18
"application" : "7f7b5180-XXXX-XXXX-9558-092397c841ef",
_18
"uri" : "http://XXXX/XXXX/XXXX/chatgroups/66021836783617/share_files",
_18
"entities" : [ ],
_18
"data" : {
_18
"file_url" : "https://XXXX/XXXX/XXXX/chatgroups/66021836783617/share_files/c6906aa0-ed19-11ea-b480-f3cf141d15c0",
_18
"group_id" : "66021836783617",
_18
"file_name" : "img_3.jpg",
_18
"created" : 1599050554954,
_18
"file_id" : "c6906aa0-XXXX-XXXX-b480-f3cf141d15c0",
_18
"file_size" : 13512
_18
},
_18
"timestamp" : 1599050554978,
_18
"duration": 0,
_18
"organization" : "XXXX",
_18
"applicationName" : "XXXX"
_18
}

Downloading the chat group shared file

Downloads a shared file of the chat group. You can get the file ID (file_id) from the response body of Retrieving the chat group shared files.

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

HTTP request


_1
GET https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/share_files/{file_id}

Path parameter

ParameterTypeDescriptionRequired
group_idStringThe group ID.Yes
file_idStringThe file ID.Yes

For other parameters and detailed descriptions, see Common parameters.

Request header

ParameterTypeDescriptionRequired
AcceptStringThe parameter type. Set it as application/json.Yes
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, and the data field in the response body contains the following parameters.

ParameterTypeDescription
file_urlStringThe URL to the chat group shared file on the Chat server.
group_idStringThe group ID.
file_nameStringThe name of the chat group shared file.
createdLongThe Unix timestamp for upload time of the chat group shared file.
file_idStringThe ID of the chat group shared file. This field is required if you want to download or remove a chat group shared file.
file_sizeNumberThe size of the group's shared file, in bytes.

For other fields and descriptions, see Public parameter.

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

Example

Request example


_1
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/chatgroups/66021836783617/share_files/b30e0be0-XXXX-XXXX-8732-172a3f85134f'

Response example


_18
{
_18
"action" : "post",
_18
"application" : "7f7b5180-XXXX-XXXX-9558-092397c841ef",
_18
"uri" : "http://XXXX/XXXX/XXXX/chatgroups/66021836783617/share_files",
_18
"entities" : [ ],
_18
"data" : {
_18
"file_url" : "https://XXXX/XXXX/XXXX/chatgroups/66021836783617/share_files/c6906aa0-ed19-11ea-b480-f3cf141d15c0",
_18
"group_id" : "66021836783617",
_18
"file_name" : "img_3.jpg",
_18
"created" : 1599050554954,
_18
"file_id" : "c6906aa0-XXXX-XXXX-b480-f3cf141d15c0",
_18
"file_size" : 13512
_18
},
_18
"timestamp" : 1599050554978,
_18
"duration": 0,
_18
"organization" : "XXXX",
_18
"applicationName" : "XXXX"
_18
}

Deleting a chat group shared file

Deletes a chat group shared file. You can get the file ID (file_id) from the response body of Retrieving the chat group shared files.

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

HTTP request


_1
DELETE https://{host}/{org_name}/{app_name}/chatgroups/{group_id}/share_files/{file_id}

Path parameter

ParameterTypeDescriptionRequired
group_idStringThe group ID.Yes
file_idStringThe file ID.Yes

For other parameters and detailed descriptions, see Common parameters.

Request header

ParameterTypeDescriptionRequired
AcceptStringThe parameter type. Set it as application/json.Yes
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, and the data field in the response body contains the following parameters.

ParameterTypeDescription
group_idStringThe group ID.
file_idStringThe ID of the chat group shared file. This field is required if you want to download or remove a shared files.
resultBooleanThe result of deleting the file:
  • true: Success.
  • false: Failure.
  • For other fields and descriptions, see Public parameter.

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

    Example

    Request example


    _1
    curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer <YourAppToken>' 'http://XXXX/XXXX/XXXX/chatgroups/66021836783617/share_files/b30e0be0-XXXX-XXXX-8732-172a3f85134f'

    Response example


    _15
    {
    _15
    "action": "delete",
    _15
    "application": "8be024f0-XXXX-XXXX-b697-5d598d5f8402",
    _15
    "uri": "http://XXXX/XXXX/XXXX/chatgroups/66021836783617/share_files/b30e0be0-e1d4-11ea-8732-172a3f85134f",
    _15
    "entities": [],
    _15
    "data": {
    _15
    "group_id": "66021836783617",
    _15
    "file_id": "b30e0be0-XXXX-XXXX-8732-172a3f85134f",
    _15
    "result": true
    _15
    },
    _15
    "timestamp": 1599049350114,
    _15
    "duration": 0,
    _15
    "organization": "XXXX",
    _15
    "applicationName": "XXXX"
    _15
    }

    Status codes

    For details, see HTTP Status Codes.

    Page Content