The app backend can use this callback to monitor users’ group messages in real time, including:
The callback is triggered before the IM backend sends a group message to group members.
In the following example, the callback URL configured in the app is https://www.example.com
.
Example:
https://www.example.com?SdkAppid=$SDKAppID&CallbackCommand=$CallbackCommand&contenttype=json&ClientIP=$ClientIP&OptPlatform=$OptPlatform
Parameter | Description |
---|---|
https | The request protocol is HTTPS, and the request method is POST. |
www.example.com | The callback URL. |
SdkAppid | The SDKAppID assigned by the IM console when an app is created. |
CallbackCommand | The value is fixed to Group.CallbackBeforeSendMsg. |
contenttype | The value is fixed to JSON. |
ClientIP | The client IP address, whose format is similar to 127.0.0.1. |
OptPlatform | The client platform. For details on the possible values, see the OptPlatform parameter in Third-Party Callback Overview: Callback Protocols. |
{
"CallbackCommand": "Group.CallbackBeforeSendMsg", // Callback command
"GroupId": "@TGS#2J4SZEAEL", // Group ID
"Type": "Public", // Group type
"From_Account": "jared", // Sender
"Operator_Account":"admin", // Request initiator
"Random": 123456, // Random number
"MsgBody": [ // Message body. For more information, see the TIMMessage message object.
{
"MsgType": "TIMTextElem", // Text
"MsgContent": {
"Text": "red packet"
}
}
]
}
Field | Type | Description |
---|---|---|
CallbackCommand | String | The callback command. |
GroupId | String | The ID of the group that generates group messages. |
Type | String | The type of the group that generates group messages, such as Public. For details, see Group Types. |
From_Account | String | The UserID of the message sender. |
Operator_Account | String | The UserID of the message initiator, based on which the system can identify whether the request is initiated by the admin. |
Random | Integer | A 32-bit random number in the message sending request. |
MsgBody | Array | The message body. For details, see Message Format Description. |
The user is allowed to send a group message, and the content of the sent message is not modified.
{
"ActionStatus": "OK",
"ErrorInfo": "",
"ErrorCode": 0 // The 0 value indicates allowing to send group messages.
}
The user is not allowed to send a group message. In this case, the message is not sent, and the error code 10016
is returned to the caller.
{
"ActionStatus": "OK",
"ErrorInfo": "",
"ErrorCode": 1 // The 1 value indicates that the user is disallowed to send group messages.
}
The user is not allowed to send a group message. In this case, the message is not sent, but a successful sending message will be returned to the caller to pretend that the message has been sent.
{
"ActionStatus": "OK",
"ErrorInfo": "",
"ErrorCode": 2 // The 2 value indicates the message is silently discarded.
}
In the following response example, the group message sent by the user is modified (in this case, a custom message is added), and the IM backend will deliver the modified message. With this feature, the app backend can add special content, such as the user level and title, to the message sent by the user.
{
"ActionStatus": "OK",
"ErrorInfo": "",
"ErrorCode": 0, // The parameter value must be 0 so that the modified message can be sent normally.
"MsgBody": [ // The message modified by the app. If no modification is made, the message sent by the user is used by default.
{
"MsgType": "TIMTextElem", // Text
"MsgContent": {
"Text": "red packet"
}
},
{
"MsgType": "TIMCustomElem", // Custom message
"MsgContent": {
"Desc": "CustomElement.MemberLevel", // Description
"Data": "LV1" // Data
}
}
]
}
Field | Type | Attribute | Description |
---|---|---|---|
ActionStatus | String | Required | The request processing result. OK: succeeded. FAIL: failed. |
ErrorCode | Integer | Required | The error code. 0: allow to send group message. 1: disallow to send group messages. 2: the sent message will be silently discarded. |
ErrorInfo | String | Required | Error information. |
MsgBody | Array | Optional | The message body modified by the app. The IM backend will send the modified message to the group. For details on the format, see Message Format Description. |
Was this page helpful?