Skip to main content

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

ParameterDescription
httpsRequest protocol is HTTPS, and the method is POST
https://callbackurlCallback URL
CallbackCommandFixed value: callbackBeforePushCommand
contenttypeFixed value: JSON
Header NameExample ValueMandatoryTypeDescription
operationID1646445464564RequiredstringoperationID 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

FieldTypeDescription
callbackCommandstringCallback command, here it is the callback before message push
platformIDintPlatform ID (e.g., 1 for iOS, 2 for Android)
platformstringPlatform name (e.g., iOS, Android)
userIDListarrayList of user IDs who will receive this message
titlestringTitle of the push message
descstringDescription or main content of the push message
exstringExtra push information
iOSPushSoundstringSound used for push messages on iOS devices
iOSBadgeCountbooleanWhether to show the number of unread messages on the iOS app icon
signalInfostringAdditional signal data for transmitting extra information
clientMsgIDstringClient message ID
sendIDstringSender ID
groupIDstringGroup ID (if the message is sent to a group)
contentTypeintID of the message content type
sessionTypeintID of the session type
atUserIDListarrayList of user IDs who are mentioned in the message
contentstringContent of the message being sent

Response Packet Example

Allow Push

Allow the message to be pushed to the client.

{
"actionCode": 0,
"errCode": 0,
"errMsg": "Success",
"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

FieldTypeDescription
actionCode0Indicates whether the business system callback was executed correctly. 0 means the operation was successful.
errCode5001Indicates 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.
nextCode1Next step instruction, 1 indicates refusal to continue execution, set when actionCode is 0.
userIDListarrayList of user IDs allowed to receive the message.
offlinePushInfoobjectObject of offline push information.