Skip to main content

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

FieldTypeDescription
sendIDstringSender's user ID
callbackCommandstringCallback command, used for callback before sending a single chat message
serverMsgIDstringServer-assigned message ID
clientMsgIDstringClient-assigned message ID
operationIDstringUsed for global tracking
senderPlatformIDint32Sender's platform ID
senderNicknamestringSender's nickname
sessionTypeint32Type of session
msgFromint32Source of the message
contentTypeint32Type of the content
statusint32Status of the message
sendTimeint64Timestamp of message sent (milliseconds)
createTimeint64Timestamp of message creation (milliseconds)
contentstringMessage content
sequint32Sequence number of the message
atUserListarrayList of group member IDs; ignore for single chat
faceURLstringURL for sender's avatar
exstringExtra data field
recvIDstringReceiver'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

FieldValueDescription
actionCode0Indicates whether the callback was successfully executed. 0 means success.
errCode5001Custom 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
nextCode1Next step directive, 1 to halt further action if actionCode is 0