Skip to main content

Callback After Sending a Single Chat Message

Function Description

The App business server can use this callback to perform real-time operations on users' single chat messages, such as:

  • Real-time recording of single chat messages (logging or synchronization to other systems).
  • Data statistics of single chat messages (counting the number of people, messages, etc.).

Precautions

  • To enable the callback, it is necessary to configure the callback URL and activate the corresponding switch for this callback protocol. Configuration methods can be found in the Callback Explanation document.
  • The direction of the callback is an HTTP/HTTPS POST request initiated by OpenIMServer to the App backend.
  • After receiving the callback request, the App business server must verify whether the command parameter in the request URL is its SDKNAME parameter.
  • The APP business server must respond to this request within the timeout period.

Scenarios That May Trigger This Callback

  • App users send single chat messages through the client.
  • App administrators send single chat messages through the REST API.

Timing of the Callback

  • After OpenIMServer receives a single chat message from a user and delivers it to the target user.

Interface Description

Request URL Example

In the following example, the callback URL configured by the App is https://callbackurl.

https://callbackurl?command=$CallbackCommand&contenttype=json

Request Parameter Description

ParameterDescription
httpsRequest protocol is HTTPS, method is POST
https://callbackurlCallback URL
CallbackCommandFixed value: callbackAfterSendSingleMsgCommand
contenttypeFixed value: JSON
Header NameExample ValueMandatoryTypeDescription
operationID1646445464564RequiredstringoperationID for global link tracing

Request Packet Example

{
"sendID": "user123",
"callbackCommand": "callbackAfterSendSingleMsgCommand",
"serverMsgID": "serverMsg123",
"clientMsgID": "clientMsg123",
"senderPlatformID": 1,
"senderNickname": "John Doe",
"sessionType": 1,
"msgFrom": 1,
"contentType": 1,
"status": 1,
"createTime": 1673048592000,
"content": "Hello, how are you?",
"seq": 1,
"atUserList": ["user456", "user789"],
"faceURL": "http://example.com/path/to/face/image.png",
"ex": "Extra data",
"recvID": "user456"
}

Request Packet Field Explanation

FieldTypeDescription
sendIDstringSender's user ID
callbackCommandstringCallback command, here for post-single chat message callback
serverMsgIDstringServer-generated message ID
clientMsgIDstringClient-generated message ID
senderPlatformIDint32Sender's platform ID
senderNicknamestringSender's nickname
sessionTypeint32Session type, 1 for single chat, 2 for group chat, 4 for system notification
msgFromint32Message origin, 100 for from user, 200 from administrators or system broadcast notifications, etc.
contentTypeint32The message content type, 101 represents a text message, 102 represents a picture message, 103 represents a voice message,...
statusint32Message status, 1 for sent successfully, 2 for failure
createTimeint64Message creation timestamp (milliseconds)
contentstringMessage content
sequint32Message sequence number
atUserListstringList of user IDs mentioned in group chat, ignored in single chat
faceURLstringSender's avatar URL
exstringAdditional data field
recvIDstringReceiver's user ID

Response Packet Example

Successful Response

After synchronizing data, the App business server sends a callback response packet.

{
"actionCode": 0,
"errCode": 0,
"errMsg": "Success",
"errDlt": ""
}

Response Packet Field Explanation

FieldValueDescription
actionCode0Indicates if the business system's callback was executed correctly. 0 means the operation was successful.
errCode0Indicatesa custom error code, here 0 means ignore the callback result.
errMsg"An error message"Simple error message corresponding to the custom error code.
errDlt"Detailed error information"Detailed error information corresponding to the custom error code.
nextCode1Next step instruction, 1 means to refuse to continue executing, set when actionCode is 0.