Callback for Modifying Message Content
Description
The App backend can use this callback to alter message content, such as removing non-compliant content or replacing sensitive words.
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 message through the client.
- A user sends a message through the REST API.
- A user sends a group message via the client.
- An administrator sends a group message via the REST API.
Timing of Callback
- Before OpenIMServer distributes the group message to group members.
Interface Description
Example Request URL
The CallbackCommand
here is: callbackBeforeMsgModifyCommand
{WEBHOOK_ADDRESS}/callbackBeforeMsgModifyCommand?contenttype=json
Example Request Package
{
"sendID": "sender123",
"callbackCommand": "callbackBeforeMsgModifyCommand",
"serverMsgID": "serverMsg123",
"clientMsgID": "clientMsg123",
"operationID": "1646445464564",
"senderPlatformID": 1,
"senderNickname": "Sender",
"sessionType": 1,
"msgFrom": 1,
"contentType": 1,
"status": 1,
"sendTime": 1673048592000,
"createTime": 1673048592000,
"content": "Hello, World!",
"seq": 123,
"atUserList": ["user123", "user456"],
"faceURL": "http://example.com/sender_face.png",
"ex": "Extra data"
}
Request Package Field Descriptions
Field | Type | Description |
---|---|---|
sendID | string | Unique identifier for the sender |
callbackCommand | string | Callback command, here used for message modification |
serverMsgID | string | Server-generated message ID |
clientMsgID | string | Client-generated message ID |
operationID | string | Used for global tracking |
senderPlatformID | int32 | Sender's platform ID |
senderNickname | string | Sender's nickname |
sessionType | int32 | Session type, indicating single or group chat |
msgFrom | int32 | Source of the message, indicating sent or received |
contentType | int32 | Type of message content |
status | int32 | Status of the message |
sendTime | int64 | Timestamp when the message was sent (milliseconds) |
createTime | int64 | Timestamp when the message was created (milliseconds) |
content | string | Message content |
seq | uint32 | Message sequence number |
atUserList | []string | List of group member IDs |
faceURL | string | Sender's avatar URL |
ex | string | Extra data |
Example Response Package
Allow Modification
Allows modification of the message.
{
"actionCode": 0,
"errCode": 0,
"errMsg": "",
"errDlt": "",
"nextCode": 0,
"content": "Modified content",
"recvID": "receiver123",
"groupID": "group123",
"clientMsgID": "clientMsg456",
"serverMsgID": "serverMsg456",
"senderPlatformID": 1,
"senderNickname": "ModifiedSender",
"senderFaceURL": "http://example.com/modified_sender_face.png",
"sessionType": 1,
"msgFrom": 1,
"contentType": 1,
"status": 1,
"options": {
"option1": true,
"option2": false
},
"offlinePushInfo": {
"title": "Modified Notification",
"content": "Modified Content",
"pushFlag": 1,
"sound": "default",
"badge": 1
},
"atUserIDList": ["user789", "user101112"],
"msgDataList": [65, 66, 67],
"attachedInfo": "Modified Info",
"ex": "Modified Extra data"
}
Response Package Field Descriptions
Field | Type | Description |
---|---|---|
actionCode | int | Indicates if the callback was successfully executed. 0 for success. |
errCode | int | Custom error code, range between 5000-9999; set when actionCode ≠ 0 or nextCode = 1 |
errMsg | string | Simple error message for the custom error code |
errDlt | string | Detailed error information |
nextCode | int | Next action directive; 1 to halt further action if actionCode = 0 |
content | *string | Modified message content |
recvID | *string | User ID of the message receiver |
groupID | *string | Unique identifier for the group |
clientMsgID | *string | Client-generated message ID |
serverMsgID | *string | Server-generated message ID |
senderPlatformID | *int32 | Sender's platform ID |
senderNickname | *string | Modified sender nickname |
senderFaceURL | *string | Modified sender avatar URL |
sessionType | *int32 | Session type |
msgFrom | *int32 | Source of the message |
contentType | *int32 | Content type of the message |
status | *int32 | Message status |
options | *map[string]bool | Modified message options |
offlinePushInfo | *OfflinePushInfo | Modified offline push information |
atUserIDList | *[]string | List of group member IDs |
msgDataList | *[]byte | Modified message data list |
attachedInfo | *string | Modified additional information |
ex | *string | Modified extra data field |