Skip to main content

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

FieldTypeDescription
sendIDstringUnique identifier for the sender
callbackCommandstringCallback command, here used for message modification
serverMsgIDstringServer-generated message ID
clientMsgIDstringClient-generated message ID
operationIDstringUsed for global tracking
senderPlatformIDint32Sender's platform ID
senderNicknamestringSender's nickname
sessionTypeint32Session type, indicating single or group chat
msgFromint32Source of the message, indicating sent or received
contentTypeint32Type of message content
statusint32Status of the message
sendTimeint64Timestamp when the message was sent (milliseconds)
createTimeint64Timestamp when the message was created (milliseconds)
contentstringMessage content
sequint32Message sequence number
atUserList[]stringList of group member IDs
faceURLstringSender's avatar URL
exstringExtra 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

FieldTypeDescription
actionCodeintIndicates if the callback was successfully executed. 0 for success.
errCodeintCustom error code, range between 5000-9999; set when actionCode ≠ 0 or nextCode = 1
errMsgstringSimple error message for the custom error code
errDltstringDetailed error information
nextCodeintNext action directive; 1 to halt further action if actionCode = 0
content*stringModified message content
recvID*stringUser ID of the message receiver
groupID*stringUnique identifier for the group
clientMsgID*stringClient-generated message ID
serverMsgID*stringServer-generated message ID
senderPlatformID*int32Sender's platform ID
senderNickname*stringModified sender nickname
senderFaceURL*stringModified sender avatar URL
sessionType*int32Session type
msgFrom*int32Source of the message
contentType*int32Content type of the message
status*int32Message status
options*map[string]boolModified message options
offlinePushInfo*OfflinePushInfoModified offline push information
atUserIDList*[]stringList of group member IDs
msgDataList*[]byteModified message data list
attachedInfo*stringModified additional information
ex*stringModified extra data field