Callback Before Sending Single Chat Message
Description
The App backend can use this callback to take action on single chat messages in real-time, such as:
- Logging single chat messages.
- Blocking user requests with inappropriate content.
Important Notes
- To enable this callback, configure the callback URL and activate the corresponding protocol switch. For configuration details, see the Callback Introduction document.
- The callback direction is from OpenIMServer to the App backend as an HTTP/HTTPS POST request.
- The App backend must respond to this request within the specified timeout.
Scenarios that Trigger This Callback
- A user sends a single chat message through the client.
- An administrator sends a single chat message via the REST API.
Timing of Callback
- After OpenIMServer receives the user’s single chat message but before distributing it to the target user.
Interface Description
Example Request URL
The CallbackCommand
here is: callbackBeforeSendSingleMsgCommand
{WEBHOOK_ADDRESS}/callbackBeforeSendSingleMsgCommand?contenttype=json
Example Request Package
{
"sendID": "user123",
"callbackCommand": "callbackBeforeSendSingleMsgCommand",
"serverMsgID": "msg001",
"clientMsgID": "clientmsg001",
"operationID": "1646445464564",
"senderPlatformID": 1,
"senderNickname": "User123",
"sessionType": 1,
"msgFrom": 1,
"contentType": 1,
"status": 1,
"sendTime": 1673048592000,
"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 Package Field Descriptions
Field | Type | Description |
---|---|---|
sendID | string | Sender's user ID |
callbackCommand | string | Callback command, used for callback before sending a single chat message |
serverMsgID | string | Server-assigned message ID |
clientMsgID | string | Client-assigned message ID |
operationID | string | Used for global tracking |
senderPlatformID | int32 | Sender's platform ID |
senderNickname | string | Sender's nickname |
sessionType | int32 | Type of session |
msgFrom | int32 | Source of the message |
contentType | int32 | Type of the content |
status | int32 | Status of the message |
sendTime | int64 | Timestamp of message sent (milliseconds) |
createTime | int64 | Timestamp of message creation (milliseconds) |
content | string | Message content |
seq | uint32 | Sequence number of the message |
atUserList | array | List of group member IDs; ignore for single chat |
faceURL | string | URL for sender's avatar |
ex | string | Extra data field |
recvID | string | Receiver's user ID |
Example Response Package
Allow Message Sending
Allowing the user to send the message.
{
"actionCode": 0,
"errCode": 0,
"errMsg": "",
"errDlt": "",
"nextCode": 0
}
Response Package Field Descriptions
Field | Value | Description |
---|---|---|
actionCode | 0 | Indicates whether the callback was successfully executed. 0 means success. |
errCode | 5001 | Custom error code, ranges from 5000-9999, set when actionCode is not 0, or nextCode is 1 |
errMsg | "Message" | Simple error message for the custom error code |
errDlt | "Detailed information" | Detailed error message |
nextCode | 1 | Next step directive, 1 to halt further action if actionCode is 0 |