Callback For Modifying Message Content
Functional Description
The business server can modify the message content through this callback, such as modifying and replacing sensitive words.
Precautions
- To enable the callback, you must configure the callback URL and turn on the switch corresponding to this callback protocol. See the Callback Description document for configuration methods.
- The callback direction is an HTTP/HTTPS POST request initiated by OpenIMServer to the App backend.
- The APP business server must respond to this request within the timeout period.
Scenarios That May Trigger This Callback
- Before users perform message sending through the client or APP administrators through REST API
Timing of Callback
- Before sending a message.
Interface Description
Request URL Example
Here CallbackCommand is: callbackBeforeMsgModifyCommand
{WEBHOOK_ADDRESS}/callbackBeforeMsgModifyCommand?contenttype=json
Request Package Example
{
"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 Description
| Object | Type | Description |
|---|---|---|
| sendID | string | Unique identifier of the sender |
| callbackCommand | string | Callback command, here it is the message modification command callback |
| serverMsgID | string | Message ID generated by the server |
| clientMsgID | string | Message ID generated by the client |
| operationID | string | operationID used for global link tracking |
| senderPlatformID | int32 | Platform ID of the sender |
| senderNickname | string | Nickname of the sender |
| sessionType | int32 | Session type, indicating single chat or group chat |
| msgFrom | int32 | Message source, indicating whether the message is sent or received |
| contentType | int32 | Content type of the message |
| status | int32 | Status of the message |
| sendTime | int64 | Timestamp of message sending (milliseconds) |
| createTime | int64 | Timestamp of message creation (milliseconds) |
| content | string | Content of the message |
| seq | uint32 | Sequence number of the message |
| atUserList | []string | List of group member IDs |
| faceURL | string | Avatar URL of the sender |
| ex | string | Extra data field |
Response Package Example
Allow Modification
Allow modification to 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 Description
| Field | Value | Description |
|---|---|---|
| actionCode | 0 | Indicates whether the business system callback was executed correctly. 0 means the operation was successful. |
| errCode | 5001 | Custom error code, ranges from 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 execution instruction, 1 means refusing to continue execution, set when actionCode is 0. |
| content | *string | Modified message content. |
| recvID | *string | User ID receiving the message. |
| groupID | *string | Unique identifier of the group. |
| clientMsgID | *string | Message ID generated by the client. |
| serverMsgID | *string | Message ID generated by the server. |
| senderPlatformID | *int32 | Platform ID of the sender. |
| senderNickname | *string | Nickname of the sender. |
| senderFaceURL | *string | Avatar URL of the sender. |
| sessionType | *int32 | Session type. |
| msgFrom | *int32 | Message source. |
| 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 info. |
| atUserIDList | *[]string | List of group member IDs. |
| msgDataList | *[]byte | Modified message data list. |
| attachedInfo | *string | Modified attached info. |
| ex | *string | Modified extra data field. |