logo
In-app Chat
Powered Byspreading
On this page

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.

Warning

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
Note
  • The callback data needs to be decoded by UrlDecode.
  • When using the POST request method to pass parameters:
    • The parameters in the body can be directly passed in the JsonObject format, without the need to serialize them into a string format.
    • In the headers, set "Content-type" to "application/json".
  • Request endpoint: Contact ZEGOCLOUD Technical Support to configure the corresponding callback endpoint.

  • Transmission protocol: HTTPS/HTTP (HTTPS is recommended.)

Callback parameters

appidStringA unique identifier for the App.
eventStringCallback event, the return value of this callback is send_msg.
nonceStringRandom number, used to calculate signature.
signatureStringThe verification string, see Authenticating server-to-server callbacks for details.
timestampIntThe current server time in Unix timestamp format, in seconds. It is used to calculate the signature.
from_user_idStringMessage sender ID.
conv_typeIntTarget session type:
  • 0: One-on-one chat.
  • 1: Room chat.
  • 2: Group chat.
conv_idStringTarget session ID.
Note
When you use the server to send a single chat message, this field is empty and "user_list" has a value.
msg_typeIntMessage type:
  • 1: Text.
  • 11: Images.
  • 12: Files.
  • 13: Audio.
  • 14: Video.
  • 200: Custom.
sub_msg_typeIntThe 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_bodyStringMessage content.
  • When msg_type is 1 (text type) or 200 (custom type), msg_body is the message content passed in when sending a message, and you can directly read the message content.
  • When msg_type is 11, 12, 13, 14, that is, when the message is a media type, msg_body is a JSON string. Please use URLDecode to decode this JSON string, and parse this JSON string according to the multimedia message structure, and then obtain each field data in the message.
msg_idStringMessage ID, which can be used to determine the uniqueness of the message.
Warning

When sending single chat messages in batches through the server API, this field is empty. If you need to obtain the message ID at this time, please obtain it from "user_list".

msg_seqIntMessage Seq, which can be used to withdraw messages.
Warning

When sending single chat messages in batches through the server API, this field is empty. If you need to obtain the message Seq at this time, please obtain it from "user_list".

msg_timeIntThe time when the server receives the message, Unix timestamp, in milliseconds (ms).
send_resultIntMessage sending result. 0 means the sending is successful, and other integers are specific Error Codes, which means the sending failed, you can refer to return codes for the cause and solution.
user_listArray of ObjectThis field will be included in the callback only when sending a single chat message through the server, which is used to return the message receiving user information in batches.
Note
  • When this field has a value, "conv_id" is empty.
  • If you have used this callback before January 5, 2024, you will find that this field is not included in the callback. If you need the callback to support this field, please contact ZEGOCLOUD Technical Support.
└user_idStringMessage receiving user.
└msg_idStringMessage ID, which can be used to determine the uniqueness of the message. When the message fails to be sent, this field is empty.
└msg_seqIntMessage Seq, which can be used to withdraw the message.
Note

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

ParametersTypeDescription
md5StringThe MD5 value of the file.
file_nameStringFile name.
file_sizeStringFile size in bytes.
download_urlStringDownload URL.
media_durationStringAudio and Video duration, in seconds.

Callback example

  • POST/JSON
Untitled
{
    "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
}
1
Copied!

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, or the HTTP status code received by the ZEGOCLOUD server is not 2xx (such as 200), 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.

Previous

Message not sent yet

Next

Authenticating server-to-server callbacks