- Documentation
- In-app Chat
- Server APIs
- Server callbacks
- Callback on message sent
Callback on message sent
Description
After the user sends a message to one-on-one chat, group chat, or room successfully or fails, the business server can receive the message sending callback from the In-app Chat server, and synchronize the message sent by the user to the business server in real time, and store it in the business server.
The supported message types for this callback are text messages, image messages, file messages, audio messages, video messages, and custom messages. command messages and barrage messages are not supported.
Callback request
Request method: POST/JSON
The callback data needs to be decoded by UrlDecode.
Request endpoint: Contact ZEGOCLOUD Technical Support to configure the corresponding callback endpoint.
Transmission protocol: HTTPS/HTTP (HTTPS is recommended.)
Callback parameters
Public parameters | Type | Description |
---|---|---|
appid |
String |
A unique identifier for the App. |
event |
String |
Callback event, the return value of this callback is send_msg . |
nonce |
String |
Random number, used to calculate signature. |
signature |
String |
The verification string, see Authenticating server-to-server callbacks for details. |
timestamp |
Int |
The current server time in Unix timestamp format, in seconds. It is used to calculate the signature. |
Business parameters | Type | Description |
from_user_id |
String |
Message sender ID. |
conv_type |
Int |
Target session type:
|
conv_id |
String |
Target session ID. |
msg_type |
Int |
Message type:
|
sub_msg_type |
Int |
The specific custom type. The value is filled in when the user sends a custom message, and the value range is [0,200]. This parameter is meaningful only when msg_type is 200 (custom type). |
msg_body |
String |
Message content.
|
msg_id |
String |
Message ID, which can be used to determine the uniqueness of the message. |
payload |
String |
Message extension field. |
msg_time |
Int |
The time when the server receives the message, Unix timestamp, in milliseconds (ms). |
send_result |
Int |
We recommend that you convert some parameters to Int for logical processing. The relevant fields include appid
and nonce
.
msg_body JSON string parsing result parameter description
Parameters | Type | Description |
---|---|---|
md5 | String | The MD5 value of the file. |
file_name | String | File name. |
file_size | String | File size in bytes. |
download_url | String | Download URL. |
media_duration | String | Audio and Video duration, in seconds. |
Callback example
- POST/JSON
{
"appid": "1",
"event": "zim_send_msg",
"nonce": "350176",
"signature": "signature",
"timestamp": 1679553625,
"from_user_id": "350176117361",
"conv_type": 2,
"conv_id": "group1",
"msg_type": 1,
"msg_body": "msg_body",
"msg_id": "857639062792568832",
"payload": "payload",
"msg_time": 1679554146000,
"send_result": 0,
"sub_msg_type": 0
}
Return response
A status code of 2XX (such as 200) indicates success, and other responses indicate failure.
Callback retry strategy
If the ZEGOCLOUD server does not receive a response, it will retry with intervals of 2s, 4s, 8s, 16s, and 32s respectively. If the retry still fails after an interval of 32s, it will no longer retry.