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 OpenIM Server 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 OpenIM Server 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
Parameter | Description |
---|---|
https | Request protocol is HTTPS, method is POST |
https://callbackurl | Callback URL |
CallbackCommand | Fixed value: callbackAfterSendSingleMsgCommand |
contenttype | Fixed value: JSON |
Header
Header Name | Example Value | Mandatory | Type | Description |
---|---|---|---|---|
operationID | 1646445464564 | Required | string | operationID 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
Field | Type | Description |
---|---|---|
sendID | string | Sender's user ID |
callbackCommand | string | Callback command, here for post-single chat message callback |
serverMsgID | string | Server-generated message ID |
clientMsgID | string | Client-generated message ID |
senderPlatformID | int32 | Sender's platform ID |
senderNickname | string | Sender's nickname |
sessionType | int32 | Session type, 1 for single chat, 2 for group chat, 4 for system notification |
msgFrom | int32 | Message origin, 100 for from user, 200 from administrators or system broadcast notifications, etc. |
contentType | int32 | The message content type, 101 represents a text message, 102 represents a picture message, 103 represents a voice message,... |
status | int32 | Message status, 1 for sent successfully, 2 for failure |
createTime | int64 | Message creation timestamp (milliseconds) |
content | string | Message content |
seq | uint32 | Message sequence number |
atUserList | string | List of user IDs mentioned in group chat, ignored in single chat |
faceURL | string | Sender's avatar URL |
ex | string | Additional data field |
recvID | string | Receiver'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
Field | Value | Description |
---|---|---|
actionCode | 0 | Indicates if the business system's callback was executed correctly. 0 means the operation was successful. |
errCode | 0 | Indicatesa 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. |
nextCode | 1 | Next step instruction, 1 means to refuse to continue executing, set when actionCode is 0 . |