Manage chat group announcement and files

Updated

Shows how to manage the group announcement and group files by calling Agora Chat RESTful APIs.

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
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

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.
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:

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 group announcement

Retrieves the announcement of the specified group.

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

HTTP request

GET https://{host}/app-id/{app_id}/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 Common 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

curl -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer ' 'http://XXXX/app-id/XXXX/chatgroups/66021836783617/announcement'

Response example

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

Modifying the group announcement

Modifies the announcement of the specified 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

POST https://{host}/app-id/{app_id}/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

Request body

ParameterTypeDescriptionRequired
announcementStringThe content of the group announcement.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 announcement is successfully modified. true: Yes. false: No.

For other fields and descriptions, see Common 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

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

Response example

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

Retrieving the group shared files

Retrieves the shared files of the specified 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

GET https://{host}/app-id/{app_id}/chatgroups/{group_id}/share_files

// Gets a group's shared files with pagination.
GET https://{host}/app-id/{app_id}/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 group shared file. This field is required if you want to download or remove a group's shared files.
file_nameStringThe name of the group shared file.
file_ownerStringThe ID of the user uploading the shared file.
file_sizeNumberThe size of the group shared file, in bytes.
createdLongThe Unix timestamp for uploading the group shared file.

For other fields and descriptions, see Common 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

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

Response example

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

Uploading a group shared file

Uploads a 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

POST https://{host}/app-id/{app_id}/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

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 Common 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

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

Response example

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

Downloading the group shared file

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

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

HTTP request

GET https://{host}/app-id/{app_id}/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 response body contains only the content of the uploaded file. For example, the content of the uploaded file is Hello world, the response body only contains Hello world.

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

Example

Request example

curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer ' 'http://XXXX/app-id/XXXX/chatgroups/66021836783617/share_files/b30e0be0-XXXX-XXXX-8732-172a3f85134f'

Response example

The response contains only the content of the uploaded file. For example, the content of the uploaded file is Hello world, the response only contains Hello world.

Deleting a group shared file

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

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

HTTP request

DELETE https://{host}/app-id/{app_id}/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 group shared file. This field is required if you want to download or remove a shared file.
resultBooleanThe result of deleting the file: true: Success.false: Failure.

For other fields and descriptions, see Common 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

curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer ' 'http://XXXX/app-id/XXXX/chatgroups/66021836783617/share_files/b30e0be0-XXXX-XXXX-8732-172a3f85134f'

Response example

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

Status codes

For details, see HTTP Status Codes.