Callback Before 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 messages and intercepting users' inappropriate message requests.
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 before delivering 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: callbackBeforeSendSingleMsgCommand |
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": "callbackBeforeSendSingleMsgCommand",
"serverMsgID": "msg001",
"clientMsgID": "clientmsg001",
"senderPlatformID": 1,
"senderNickname": "User123",
"sessionType": 1,
"msgFrom": 1,
"contentType": 1,
"status": 1,
"createTime": 1673048592000,
"content": "Hello, this is a test message",
"seq": 1001,
"atUserList": ["user456", "user789"],
"faceURL": "http://example.com/path/to/user/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 pre-single chat message callback |
serverMsgID | string | Server-assigned message ID |
clientMsgID | string | Client-assigned message ID |
senderPlatformID | int32 | Sender's platform ID |
senderNickname | string | Sender's nickname |
sessionType | int32 | Session type |
msgFrom | int32 | Message origin |
contentType | int32 | Type of message content |
status | int32 | Message status |
createTime | int64 | Message creation timestamp (milliseconds) |
content | string | Message content |
seq | uint32 | Message sequence number |
atUserList | array | List of group member IDs, ignored in single chat |
faceURL | string | Sender's avatar URL |
ex | string | Additional data field |
recvID | string | Receiver's user ID |
Response Packet Example
Allow Sending
Allows the user to send the message.
{
"actionCode": 0,
"errCode": 0,
"errMsg": "Success",
"errDlt": "",
"nextCode": 0
}
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 | 5001 | Custom error code, ranging between 5000-9999. Set when actionCode is not 0; set when nextCode is 1. |
errMsg | "Message" | Simple error message corresponding to the custom error code. |
errDlt | "Detailed 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 . |