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
Parameter | Description |
---|---|
https | Request protocol is HTTPS, request method is POST. |
https://callbackurl | Callback URL |
CallbackCommand | Fixed value: callbackBeforeSendGroupMsgCommand |
contenttype | Fixed value: JSON |
Header
Header Name | Example Value | Optional | Type | Description |
---|---|---|---|---|
operationID | 1646445464564 | Required | string | operationID 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
Field | Type | Description |
---|---|---|
sendID | string | Unique identifier of the sender |
callbackCommand | string | Callback command, here for before sending group messages |
serverMsgID | string | Server-generated message ID |
clientMsgID | string | Client-generated message ID |
senderPlatformID | int32 | Platform ID of the sender |
senderNickname | string | Nickname of the sender |
sessionType | int32 | Type of session |
msgFrom | int32 | Origin of the message, 1 for user, 2 for group |
contentType | int32 | Type of message content |
status | int32 | Status of the message |
createTime | int64 | Timestamp of message creation (milliseconds) |
content | string | Content of the message |
seq | uint32 | Sequence number of the message |
atUserList | string | List of user IDs mentioned in the group |
faceURL | string | URL of the sender's face image |
ex | string | Additional data field |
groupID | string | Group 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
Field | Value | Description |
---|---|---|
actionCode | 0 | Indicates whether the business system's callback was executed correctly. 0 means the operation was successful. |
errCode | 5001 | Represents 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
. |