Callback Before Message Push in Online Status
Function Description
Before sending messages to the client, the App business server can receive the request of sending messages through this callback. The business server can intercept, modify, or add additional push information to the message as needed.
Precautions
- To enable the callback, a callback URL must be configured, and the switch corresponding to this callback protocol must be turned on. See the Callback Instructions document for configuration methods.
- The direction of the callback is an HTTP/HTTPS POST request initiated by OpenIM Server to the App backend.
- After receiving the callback request, the App business server needs to respond within the timeout period.
Scenarios That May Trigger This Callback
- Group member leaves the group.
- Group member is removed from the group.
- Dissolution of the group.
Timing of the Callback
- Before OpenIM Server prepares to push messages to the client.
Interface Description
Request URL Example
In the following example, the callback URL configured by the App is https://callbackurl
.
https://callbackurl?command=$CallbackCommand&contenttype=json
Request Parameters Description
Parameter | Description |
---|---|
https | Request protocol is HTTPS, and the method is POST |
https://callbackurl | Callback URL |
CallbackCommand | Fixed value: callbackBeforePushCommand |
contenttype | Fixed value: JSON |
Header
Header Name | Example Value | Mandatory | Type | Description |
---|---|---|---|---|
operationID | 1646445464564 | Required | string | operationID is used for global link tracking |
Request Packet Example
{
"callbackCommand": "callbackBeforePushCommand",
"platformID": 1,
"platform": "iOS",
"userIDList": ["user123", "user456"],
"title": "New Message",
"desc": "You have a new message",
"ex": "Extra push info",
"iOSPushSound": "default",
"iOSBadgeCount": true,
"signalInfo": "Signal data",
"clientMsgID": "msg123",
"sendID": "user789",
"groupID": "group123",
"contentType": 1,
"sessionType": 2,
"atUserIDList": ["user101", "user102"],
"content": "Hello, this is a test message"
}
Request Packet Fields Explanation
Field | Type | Description |
---|---|---|
callbackCommand | string | Callback command, here it is the callback before message push |
platformID | int | Platform ID (e.g., 1 for iOS, 2 for Android) |
platform | string | Platform name (e.g., iOS, Android) |
userIDList | array | List of user IDs who will receive this message |
title | string | Title of the push message |
desc | string | Description or main content of the push message |
ex | string | Extra push information |
iOSPushSound | string | Sound used for push messages on iOS devices |
iOSBadgeCount | boolean | Whether to show the number of unread messages on the iOS app icon |
signalInfo | string | Additional signal data for transmitting extra information |
clientMsgID | string | Client message ID |
sendID | string | Sender ID |
groupID | string | Group ID (if the message is sent to a group) |
contentType | int | ID of the message content type |
sessionType | int | ID of the session type |
atUserIDList | array | List of user IDs who are mentioned in the message |
content | string | Content of the message being sent |
Response Packet Example
Allow Push
Allow the message to be pushed to the client.
{
"actionCode": 0,
"errCode": 0,
"errMsg": "",
"errDlt": "",
"nextCode": "",
"userIDList": ["user123", "user456"],
"offlinePushInfo": {
"title": "New Message",
"desc": "You have a new message",
"ex": "Extra push info",
"iOSPushSound": "default",
"iOSBadgeCount": true,
"signalInfo": "Signal data"
}
}
Response Packet Fields Explanation
Field | Type | Description |
---|---|---|
actionCode | 0 | Indicates whether the business system callback was executed correctly. 0 means the operation was successful. |
errCode | 5001 | Indicates a custom error code, ranging between 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 step instruction, 1 indicates refusal to continue execution, set when actionCode is 0 . |
userIDList | array | List of user IDs allowed to receive the message. |
offlinePushInfo | object | Object of offline push information. |