Skip to main content

Callback Before Sending Group Messages

Function Description

The App backend can use this callback to real-time view users' group messages, including:

  • Real-time recording of group messages (for example, logging or syncing with other systems).
  • Intercepting users' requests to speak in the group.

Precautions

  • To enable the callback, you must configure the callback URL and activate the switch corresponding to this callback protocol. See the Callback Description document for configuration methods.
  • The direction of the callback is an HTTP/HTTPS POST request initiated by OpenIM Server to the App backend.
  • The App business server needs to verify whether the command parameter in the request URL is its own SDKNAME parameter after receiving the callback request.
  • The APP business server is required to respond to this request within the timeout period.

Scenarios That May Trigger This Callback

  • 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 configured callback URL of the App is https://callbackurl.

https://callbackurl?command=$CallbackCommand&contenttype=json

Request Parameter Description

ParameterDescription
httpsRequest protocol is HTTPS, request method is POST.
https://callbackurlCallback URL
CallbackCommandFixed value: callbackBeforeSendGroupMsgCommand
contenttypeFixed value: JSON
Header NameExample ValueOptionalTypeDescription
operationID1646445464564RequiredstringoperationID used for global tracing

Request Packet Example

{
"sendID": "123456",
"callbackCommand": "callbackBeforeSendGroupMsgCommand",
"serverMsgID": "msg123",
"clientMsgID": "client123",
"senderPlatformID": 1,
"senderNickname": "John",
"sessionType": 2,
"msgFrom": 1,
"contentType": 1,
"status": 0,
"createTime": 1673048592000,
"content": "Hello, this is a group message!",
"seq": 1,
"atUserList": ["user123", "user456"],
"faceURL": "http://example.com/user123.png",
"ex": "Extra data",
"groupID": "group567"
}

Request Packet Field Description

FieldTypeDescription
sendIDstringUnique identifier of the sender
callbackCommandstringCallback command, here for before sending group messages
serverMsgIDstringServer-generated message ID
clientMsgIDstringClient-generated message ID
senderPlatformIDint32Platform ID of the sender
senderNicknamestringNickname of the sender
sessionTypeint32Type of session
msgFromint32Origin of the message, 1 for user, 2 for group
contentTypeint32Type of message content
statusint32Status of the message
createTimeint64Timestamp of message creation (milliseconds)
contentstringContent of the message
sequint32Sequence number of the message
atUserListstringList of user IDs mentioned in the group
faceURLstringURL of the sender's face image
exstringAdditional data field
groupIDstringGroup ID

Response Packet Example

Allowing Sending

Allowing the user to send the group message.

{
"actionCode": 0,
"errCode": 0,
"errMsg": "Success",
"errDlt": "",
"nextCode": 0
}

Response Packet Field Description

FieldValueDescription
actionCode0Indicates whether the business system's callback was executed correctly. 0 means the operation was successful.
errCode5001Represents a custom error code, 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 refuse to continue execution, set when actionCode is 0. |