Message management
This page shows how to call Chat RESTful APIs to send different types of messages, upload and download files, and retrieve historical messages.
Before calling the following methods, make sure you understand the call frequency limit of the Chat RESTful APIs as described in Limitations.
Common parameters
The following table lists common request and response parameters of the Chat RESTful APIs:
Request parameters
Parameter | Type | Description | Required |
---|---|---|---|
host | String | The 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_name | String | The unique identifier assigned to each company (organization) by the Chat service. For how to get the org name, see Get the information of the Chat project. | Yes |
app_name | String | The unique identifier assigned to each app by the Chat service. For how to get the app name, see Get the information of the Chat project. | Yes |
username | String | 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:
| Yes |
Response parameters
Parameter | Type | Description |
---|---|---|
action | String | The request method. |
organization | String | The unique identifier assigned to each company (organization) by the Chat service. This is the same as org_name . |
application | String | A unique internal ID assigned to each app by the Chat service. You can safely ignore this parameter. |
applicationName | String | The unique identifier assigned to each app by the 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. |
entities | JSON | The response entity. |
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. |
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:
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.
Send a message
This group of methods enable you to send and receive peer-to-peer and group messages. Message types include text, image, voice, video, command, extension, file, and custom messages.
For each App Key, the call frequency limit of this method is 100 per second.
Follow the instructions below to implement sending messages:
- For text, command, and custom messages: Call the send-message method, and pass in the message content in the request body.
- For image, voice, video, and file messages:
- Call the upload-file method to upload images, voice messages, videos, or other types of files, and get the file
file_uuid
from the response body. - Call the send-message method, and pass the
file_uuid
in the request body.
- Call the upload-file method to upload images, voice messages, videos, or other types of files, and get the file
- When calling the RESTful APIs to send a message, you can use the
from
field to specify the message sender. - The maximum data length of the request body and extension fields is 5 KB, or the error 413 will be returned.
Send a one-to-one message
This method sends a message to a peer user.
HTTP request
Path parameter
For the descriptions of the path parameter, see Common Parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The content type. Set it to application/json . | Yes |
Accept | String | The content type. Set it to application/json . | Yes |
Authorization | String | The 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 parameters:
Parameter | Type | Description | Required |
---|---|---|---|
from | String | The username of the message sender. If you do not set this field, the Chat server takes the admin as the sender. If you set it as the empty string "", this request fails. | No |
to | Array | An array of the usernames of the message recipients. For each request, you can send a message to a maximum of 600 users. Within one minute, you can send messages to a maximum of 6,000 users. | Yes |
type | String | The message type:
| Yes |
body | JSON | The message content. For different message types, this parameter contains different fields. For details, see Body of different message types. | Yes |
sync_device | Bool | Whether to synchronize the message to the message sender.
| No |
routetype | String | Whether the message is delivered only when the recipient(s) is/are online:
| No |
ext | JSON | The extension field of the message. It cannot be null . | No |
ext.em_ignore_notification | Bool | Whether to send a silent message:
| No |
Body of different message types
-
Text message
Parameter Type Description Required msg
String The message content. Yes -
Image message
Parameter Type Description Required filename
String The name of the image file. You are advised to pass in this parameter, or there is no image name displayed on the client that receives the message. No secret
String The secret for accessing the image file. You can obtain the value of secret
from theshare-secret
parameter in the response body of the upload method. If you setrestrict-access
astrue
in the request header ofupload
when uploading the image file, ensure that you set this parameter.No size
JSON The size of the image (in pixels). This parameter contains two fields: - height: The image height.
- width: The image width.
No url
String The URL address of the image file, in the format of https://{host}/{org_name}/{app_name}/chatfiles/{file_uuid}
, in whichfile_uuid
can be obtained from the response body ofupload
after you upload the file to the server.Yes -
Voice message
Parameter Type Description Required filename
String The name of the audio file. You are advised to pass in this parameter, or there is no voice file name displayed on the client that receives the message. No secret
String The secret for accessing the audio file. You can obtain the value of secret
from theshare-secret
parameter in the response body of the upload method. If you setrestrict-access
astrue
in the request header ofupload
when uploading the audio file, ensure that you set this parameter.No length
Int The length of the audio file (in seconds). No url
String The URL address of the audio file, in the format of https://{host}/{org_name}/{app_name}/chatfiles/{file_uuid}
, in whichfile_uuid
can be obtained from the response body ofupload
after you upload the file to the server.Yes -
Video message
Parameter Type Description Required filename
String The name of the video file. You are advised to pass in this parameter, or there is no video file name displayed on the client that receives the message. No thumb
String The URL address of the video thumbnail, in the format of https://{host}/{org_name}/{app_name}/chatfiles/{file_uuid}
, in whichfile_uuid
can be obtained from the response body ofupload
after you upload the file to the server.No length
Int The length of the video file (in seconds). No secret
String The secret for accessing the video file. You can obtain the value of secret
from theshare-secret
parameter in the response body of the upload method. If you setrestrict-access
astrue
in the request header ofupload
when uploading the video file, ensure that you set this parameter.No file_length
Long The data length of the video file (in bytes). No thumb_secret
String The secret for accessing the video thumbnail. You can obtain the value of thumb_secret
from theshare-secret
parameter in the response body of the upload method. If you setrestrict-access
astrue
in the request header ofupload
when uploading the thumbnail, ensure that you set this parameter.No url
String The URL address of the video file, in the format of https://{host}/{org_name}/{app_name}/chatfiles/{file_uuid}
, in whichfile_uuid
can be obtained from the response body ofupload
after you upload the file to the server.Yes -
File message
Parameter Type Description Required filename
String The name of the file. You are advised to pass in this parameter, or there is no file name displayed on the client that receives the message. Yes secret
String The secret for accessing the file. You can obtain the value of secret
from theshare-secret
parameter in the response body of the upload method. If you setrestrict-access
astrue
in the request header ofupload
when uploading file, ensure that you set this parameter.No url
String The URL address of the file, in the format of https://{host}/{org_name}/{app_name}/chatfiles/{file_uuid}
, in whichfile_uuid
can be obtained from the response body ofupload
after you upload the file to the server.Yes -
Location message
Parameter Type Description Required lat
String The latitude of the location (in degrees). Yes lng
String The longitude of the location (in degrees). Yes addr
String The address of the location. Yes -
CMD message
Parameter Type Description Required action
String The content of the command. Yes -
Custom message
Parameter Type Description Required customEvent
String The event type customized by the user. The value of this parameter should be a regular expression, for example, [a-zA-Z0-9-_/\.]{1,32}
.No customExts
JSON The event attribute customized by the user. The data type is Map<String,String>
. You can set a maximum of 16 elements.No
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following parameters:
Parameter | Type | Description |
---|---|---|
data | JSON | The detailed content of the response. The value of this parameter includes a key-value pair where key represents the username of the message recipient and value the message ID. For example, if the returned data is "user2":"1029457500870543736" , it means that user2 has sent a message with the ID of 1029457500870543736. |
For the other parameters and descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible causes.
Example
Request example
-
Send a text message to the specified user without synchronizing the message with the sender
-
Send a text message to the online user while synchronizing the message with the sender
-
Send an image message
-
Send a voice message
-
Send a video message
-
Send a file message
-
Send a location message
-
Send a CMD message
-
Send a custom message
Response example
-
Send a text message
-
Send an image message
-
Send a voice message
-
Send a video message
-
Send a file message
-
Send a location message
-
Send a CMD message
-
Send a custom message
Send a group message
HTTP request
Path parameter
For the descriptions of the path parameter, see Common Parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The content type. Set it to application/json . | Yes |
Accept | String | The content type. Set it to application/json . | Yes |
Authorization | String | The 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 parameters:
Parameter | Type | Description | Required |
---|---|---|---|
to | Array | An array of the group IDs that receives the message. Within one second, you can send a maximum of 20 messages to a chat group, and for each request, you can send messages to a maximum of 3 chat groups. | Yes |
need_group_ack | Boolean | Whether read receipts are required after the message is sent:
| No |
The other parameters and descriptions are the same with those of Sending a one-to-one message method.
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following parameters:
Parameter | Type | Description |
---|---|---|
data | JSON | The detailed content of the response. The value of this parameter includes a key-value pair where key represents the group ID that receives the message and value the message ID. For example, if the returned data is "184524748161025": "1029544257947437432" , it means that a message with the ID of 1029544257947437432 is sent in chat group 184524748161025. |
For the other parameters and descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible causes.
Example
Request example
-
Send a text message to all members in a chat group whether they are online or not
-
Send a text message to online users in a chat group by setting
routetype
toROUTE_ONLINE
. -
Send an image message
-
Send a voice message
-
Send a video message
-
Send a file message
-
Send a location message
-
Send a CMD message
-
Send a Custom message
Response example
-
Send a text message
-
Send an image message
-
Send a voice message
-
Send a video message
-
Send a file message
-
Send a location message
-
Send a CMD message
-
Send a custom message
Send a chat room message
This RESTful API allows you to send a maximum of 100 messages to 10 chat rooms in total on each call. Assuming that you send two messages to 10 chat rooms, the server counts it as 20 messages.
You can set the priority of a certain message type or chat room member to high, normal, or low. In this case, when the server is overloaded, low-priority messages can be dropped to reserve resources for the high-priority ones. This ensures that high-priority messages are sent first.
Note that this feature can increase the delivery reliability of high-priority messages, but cannot guarantee the deliveries. Even high-priorities messages can be dropped when the server load goes too high.
HTTP request
Path parameter
For the descriptions of the path parameter, see Common Parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The content type. Set it to application/json . | Yes |
Accept | String | The content type. Set it to application/json . | Yes |
Authorization | String | The 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 parameters:
Parameter | Type | Description | Required |
---|---|---|---|
to | Array | An array of the chat room IDs that receives the message. Within one second, you can send messages to a maximum of 100 chat rooms, and for each request, you can send messages to a maximum of 10 chat rooms. | Yes |
chatroom_msg_level | String | The chat room message priority:
| No |
The other parameters and descriptions are the same with those of Sending a one-to-one message method.
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following parameters:
Parameter | Type | Description |
---|---|---|
data | JSON | The detailed content of the response. The value of this parameter includes a key-value pair where key represents the chat room ID that receives the message and value the message ID. For example, if the returned data is "185145305923585": "1029545553039460728" , it means that a message with the ID of 1029545553039460728 is sent in chat room 185145305923585. |
For the other parameters and descriptions, see Common parameters.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible causes.
Example
Request example
-
Send a text message to members in a chat room
-
Send an image message
-
Send a voice message
-
Send a video message
-
Send a file message
-
Send a location message
-
Send a CMD message
-
Send a custom message
Response example
-
Send a text message
-
Send an image message
-
Send a voice message
-
Send a video message
-
Send a file message
-
Send a location message
-
Send a CMD message
-
Send a custom message
Upload a file
This method enables you to upload images, audios, videos, or other types of files. For images and videos that have thumbnails, note the following:
- Images: After uploading an image, the Agora server automatically generates the thumbnail of the image.
- Videos: The Agora server does not generate thumbnails for videos automatically. After uploading a video, you must recall this method to upload the thumbnail for the video yourself.
File size | Thumbnail size |
---|---|
≤10 MB | The size of the thumbnail remains the same as that of the original file. |
10 MB | A thumbnail is generated based on the specified thumbnail-height and thumbnail-width parameters. |
If you leave thumbnail-height and thumbnail-width empty, the height and width of the thumbnail is 170 × 170 pixels by default. |
Take note of the following considerations before calling this method:
- You cannot upload a file larger than 10 MB.
- You can restrict access to the uploaded file by requiring users to provide an access key before they can download the file. The format of the key is
{{url}}?share-secret={{secret}}
.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Content-Type | String | The content type. Pass multipart/form-data | Yes |
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. | Yes |
restrict-access | Bool | Whether to restrict access to this file.
| No |
Request body
The request body is in the form-data format and contains the following fields:
Field | Type | Description | Required |
---|---|---|---|
file | String | The local path of the file to be uploaded. | Yes |
thumbnail-height | Number | The height of the image thumbnail, in pixels. This parameter is valid only if the size of the uploaded image exceeds 10 KB. If you leave this parameter empty, the height is 170 pixels by default. | No |
thumbnail-width | Number | The width of the image thumbnail, in pixels. This parameter is valid only if the size of the uploaded image exceeds 10 KB. If you leave this parameter empty, the width is 170 pixels by default. | No |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Field | Type | Description |
---|---|---|
entities.uuid | String | The file ID, a unique ID assigned to the file by the Chat service. You need to save this uuid yourself, and provide it when calling the Send-file-messages method. |
entities.type | String | File type: chatfile . |
entities.share-secret | String | The file access key. You need to save the share-secret yourself for use when downloading the file. |
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
Response example
Download a file
This method downloads images, audio, video, or other types of files.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Required | Description |
---|---|---|---|
file_uuid | String | Yes | The UUID of the file to be downloaded. |
For the other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | The content type. Set it toapplication/octet-stream , which means to download files in binary data stream format. | Yes |
Authorization | String | The 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 |
share-secret | String | The file access key for downloading the file. After the file is uploaded successfully using the Upload the file method, you can obtain the access key from the response body of upload . | This field is mandatory if you set restrict-access to true when uploading the file. |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds. You can refer to Common parameters for the parameters and detailed description.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Download a thumbnail
When uploading an image or video file, the Chat server can create a thumbnail for the file. This method has an extra thumbnail
field in the request header compared with downloading a file.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Required | Description |
---|---|---|---|
file_uuid | String | Yes | The UUID that the server generates for the thumbnail. |
For the other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Description | Required |
---|---|---|---|
Accept | String | application/octet-stream , which means to download files in binary data stream format. | Yes |
Authorization | String | Bearer ${YourAppToken} | Yes |
thumbnail | Bool | Whether to download the thumbnail of the image or video file.
| No. |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds. You can refer to Common parameters for the parameters and detailed description.
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Retrieve historical messages
This method retrieves historical messages sent and received by the user.
- For each request, you can retrieve all the historical messages sent and received within one hour from the specified time.
- Messages cannot be retrieved in real time. For example, at 9 a.m., you can retrieve messages that are sent or received at 8 a.m.
- The default storage time of historical messages differs by plan version. For details, see package details.
For each App Key, the call frequency limit of this method is 10 per minute.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
time | String | The start time of the historical messages to query. UTC time, using the ISO8601 standard, in the format yyyyMMddHH . For example, if time is 2018112717 , it means to query historical messages from 17:00 on November 27, 2018 to 18:00 on November 27, 2018. | Yes |
For other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Description | Required |
---|---|---|
Accept | String | The content type. Set it to application/json . |
Authorization | 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. | Yes |
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
url | String | The download address of the historical message file. This parameter is valid within a limited time duration. The Expires field indicates when the returned URL is valid. Once the URL expires, you need to call this method to get the URL again. |
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
Response example
Content of historical messages
After successfully querying historical messages, you can visit the URL to download the historical message file and view the specific content of the historical message.
Historical messages contain the following parameters in JSON format:
Parameter | Type | Description |
---|---|---|
msg_id | String | The message ID. |
timestamp | Long | The UTC Unix timestamp when the message is sent, in miliseconds. |
from | String | The username that sends the message. |
to | String | The message recipient.
|
chat_type | String | The chat type:
|
payload | JSON | The content of the message, including message extensions and customzied message attributes. |
The fields of bodies
for different message types vary:
-
Text messages
Field Type Description msg
String The message content. type
String The message type. For text messages, set it as txt
.Example:
-
Image messages
Field Type Description file_length
Number The size of the image attachment, in bytes. file_name
String The name of the image file. secret
String The image file access key.
This field exists if you set the access restriction when calling the upload-file method.size
Number The size of the image, in pixels. height
: The image heightwidth
: The image widthtype
String The message type. For image messages, set it as img
.url
String The URL address of the image. Example:
-
Location messages
Field Type Description addr
String The descriptions of the location. lat
Number The latitude of the location. lng
Number The longitude of the location. type
String The message type. For location messages, set it as loc
.Example:
-
Voice messages
Field Type Description file_length
Number The size of the audio file, in bytes. filename
String The audio file name, including a suffix that indicates the the audio file format. secret
String The audio file access key.
This field exists if you set the access restriction when calling the upload-file method.length
Number The duration of the audio file, in seconds. type
String The message type. For voice messages, set it as audio
.url
String The URL address of the audio file. Example:
-
Video messages
Field Type Description file_length
Number The size of the video file, in bytes. filename
String The video file name, including a suffix that indicates the video file format. secret
String The video file access key.
This field exists if you set the access restriction when calling the upload-file method.length
Number The video duration, in seconds. size
Number The video thumbnail size, in pixels. width
: The width of the video thumbnailheight
: The height of the video thumbnailthumb
String The URL address of the video thumbnail. thumb_secret
String The thumbnail file access key.
This field exists if you set the access restriction when calling the upload-file method.type
String The message type. For video messages, set it as video
.url
String The URL address of the video file. You can visit this URL to download video files. Example:
-
File messages
Field Type Descriptions file_length
Number The file size, in bytes. filename
String The file name, including a suffix that indicates the file format. secret
String The file access key.
This field exists if you set the access restriction when calling the upload-file method.type
String The message type. For file messages, set it as file
.url
String The URL address of the file. You can visit this URL to download video files. Example:
-
CMD messages
Field Type Description action
String The request method. type
String The message type. For command messages, set it as cmd
.Example:
-
Custom messages
Field Type Description customExts
JSON The custom extension properties. You can set the fields in the extension properties yourself. customEvent
String The custom event type. type
String The message type. For custom messages, set it as custom
.Example:
Recall a message
Once a message is sent, you can call this API to recall it. This API recalls a message that is saved both locally and on the server, whether it is a historical message, offline message or a roaming message on the server, or a message in the memory or local database of the message sender or recipient.
The default time limit for recalling a message is two minutes. You can extend this time frame to up to 7 days in Agora Console. To do so, select a project that enables Agora Chat, then click Configure > Features > Message recall.
For each App Key, the call frequency limit of this method is 100 per second.
Path parameter
For the parameters and detailed descriptions, see Common parameters.
Request header
HTTP request
Parameter | Type | Required | Description |
---|---|---|---|
Accept | String | The content type. Set it to application/json . | Yes |
Authorization | String | Yes | 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. |
Request body
Parameter | Type | Required | Description |
---|---|---|---|
msg_id | String | Yes | The ID of the message to recall. As only one message can be recalled each time, you can pass in only one message ID. |
to | String | Yes | The user, chat group, or chat room that receives the message to recall. You can specify a user ID, a chat group ID, or a chat room ID. Note: If the message to recall no longer exists on the server, only the message on the recipient client is recalled. |
chat_type | String | Yes | The type of the chat where the message to recall is sent.
|
from | String | No | The user who recalls the message. By default, the recaller is the app admin. You can also specify another user as the recaller. |
force | bool | No | Whether to allow to recall messages beyond the storage time on the server. For details on the message storage duration on the server, see Message storage duration.
|
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Type | Description |
---|---|---|
msg_id | String | The ID of the recalled message. |
recalled | String | Returns yes if the request is successful. |
from | String | The user who recalls the message. By default, the recaller is the app admin. |
to | String | The user, chat group, or chat room that receives the recalled message. |
chattype | String | The type of the chat where the recalled message is located.
|
For other fields and detailed descriptions, see Common parameters.
If the request fails, refer to Status codes for possible reasons.
Example
Request example
Response example
-
If the message is recalled:
-
If the message fails to be recalled:
Possible causes for failing to recall the message include the following:
"can't find message to"
: The recipient of the message to recall is not found."exceed call time limit"
: The time limit for recalling a message is exceeded."not_found msg"
: The message is already recalled or no longer exists because its storage period expires."internal error"
: An internal error occurs with the back-end service.
Delete conversations one way from the server
This method enables the chat user to delete conversations one way from the server. Once the conversation is deleted, this chat user can no longer retrieve the conversation from the server. Other chat users can still get the conversation from the server.
For each App Key, the call frequency limit of this method is 100 per second.
HTTP request
Path parameter
Parameter | Type | Description | Required |
---|---|---|---|
userName | String | The username whose conversation is to be deleted. | Yes |
For the other parameters and detailed descriptions, see Common parameters.
Request header
Parameter | Type | Required | Description |
---|---|---|---|
Authorization | String | Yes | 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. |
Request body
Parameter | Type | Required | Description |
---|---|---|---|
channel | String | Yes | The ID of the conversation that you want to delete. |
type | String | Yes | The type of the chat.
|
delete_roam | Bool | Yes | Whether to delete the chat from the server:
|
HTTP response
Response body
If the returned HTTP status code is 200
, the request succeeds. The response body contains the following fields:
Parameter | Description |
---|---|
result | Returns ok if the request is successful. |
If the returned HTTP status code is not 200
, the request fails. You can refer to Status codes for possible reasons.
Example
Request example
Response example
Import a one-to-one chat message
This method imports a one-to-one message. You can import only one message each time.
HTTP request
Request header
Parameter | Type | Required | Description |
---|---|---|---|
Authorization | String | Yes | 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. |
Request body
Parameter | Type | Description | Required |
---|---|---|---|
from | String | The username of the message sender. | Yes |
target | String | The username of the message recipient. | Yes |
type | String | The message type:
| Yes |
body | JSON | The message content. For different message types, this parameter contains different fields. For details, see Body of different message types. | Yes |
is_ack_read | Bool | Whether to set the message as read.
| No |
msg_timestamp | Long | The timestamp for importing the messages, in milliseconds. If you leave this parameter empty, the server automatically sets it as the current time. | No |
need_download | Bool | Whether to download the attachment and upload it to the server:
| No |
HTTP Response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Description |
---|---|
msg_id | The ID of the imported messages. |
For other fields and detailed descriptions, see Common parameters.
If the request fails, refer to Status codes for possible reasons.
Example
Request example
-
Import a text message
-
Import an image message
Response example
Import a chat group message
This method imports a chat group message. You can import only one message each time.
HTTP request
Request header
Parameter | Type | Required | Description |
---|---|---|---|
Authorization | String | Yes | 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. |
Request body
Parameter | Type | Description | Required |
---|---|---|---|
from | String | The username of the message sender. | Yes |
target | String | The chat group ID that receives the message. | Yes |
type | String | The message type:
| Yes |
body | JSON | The message content. For different message types, this parameter contains different fields. For details, see Body of different message types. | Yes |
is_ack_read | Bool | Whether to set the message as read.
| No |
msg_timestamp | Long | The timestamp for importing the messages, in milliseconds. If you leave this parameter empty, the server automatically sets it as the current time. | No |
need_download | Bool | Whether to download the attachment and upload it to the server:
| No |
HTTP Response
Response body
If the returned HTTP status code is 200
, the request succeeds, and the response body contains the following fields:
Parameter | Description |
---|---|
msg_id | The ID of the imported messages. |
For other fields and detailed descriptions, see Common parameters.
If the request fails, refer to Status codes for possible reasons.
Example
Request example
-
Import a text message
-
Import an image message
Response example
Status codes
For details, see HTTP Status Codes.