Callback for Modifying Message Content
Function Description
The App business server can use this callback to modify message content, such as replacing non-compliant content or sensitive words.
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 messages through the client.
- App users send messages through the REST API.
- App users send group messages through the client.
- App administrators send group messages through the REST API.
Timing of the Callback
- Before OpenIM Server delivers the group message to group members.
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: callbackMsgModifyCommandCommand |
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": "sender123",
"callbackCommand": "callbackMsgModifyCommandCommand",
"serverMsgID": "serverMsg123",
"clientMsgID": "clientMsg123",
"senderPlatformID": 1,
"senderNickname": "Sender",
"sessionType": 1,
"msgFrom": 1,
"contentType": 1,
"status": 1,
"createTime": 1673048592000,
"content": "Hello, World!",
"seq": 123,
"atUserList": ["user123", "user456"],
"faceURL": "http://example.com/sender_face.png",
"ex": "Extra data"
}
Request Packet Field Explanation
Field | Type | Description |
---|---|---|
sendID | string | Unique identifier of the sender |
callbackCommand | string | Callback command, here for message modification 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, indicating one-on-one or group chat |
msgFrom | int32 | Message origin, indicating sent or received |
contentType | int32 | Content type of the message |
status | int32 | Status of the message |
createTime | int64 | Message creation timestamp (milliseconds) |
content | string | Content of the message |
seq | uint32 | Message sequence number |
atUserList | []string | List of group member IDs mentioned |
faceURL | string | Sender's avatar URL |
ex | string | Additional data field |
Response Packet Example
Allow Modification
Allows modification of the message.
{
"actionCode": 0,
"errCode": 0,
"errMsg": "Success",
"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 Packet Field Explanation
Field | Type | 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 | "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 . |
content | string | Modified message content. |
recvID | string | Receiver's user ID. |
groupID | string | Unique identifier of the group. |
clientMsgID | string | Client-generated message ID. |
serverMsgID | string | Server-generated message ID. |
senderPlatformID | int32 | Sender's platform ID. |
senderNickname | string | Modified sender's nickname. |
senderFaceURL | string | Modified sender's avatar URL. |
sessionType | int32 | Session type. |
msgFrom | int32 | Message origin. |
contentType | int32 | Content type of the message. |
status | int32 | Status of the message. |
options | map[string]bool | Modified message options. |
offlinePushInfo | OfflinePushInfo | Modified offline push information. |
atUserIDList | []string | List of mentioned group member IDs. |
msgDataList | []byte | Modified message data list. |
attachedInfo | string | Modified additional information. |
ex | string | Modified additional data field. |