This API is used by the app backend to monitor a user’s one-to-one chat messages in real time, including:
The IM backend has received a one-to-one chat message sent by a user but has not delivered the message to the target user.
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 | Specifies that the request protocol is HTTPS and the request method is POST. |
www.example.com | Callback URL |
SdkAppid | The SDKAppID assigned via the IM console when the application is created. |
CallbackCommand | The value is fixed to C2C.CallbackBeforeSendMsg. |
contenttype | The value is fixed to JSON in the request packet body. |
ClientIP | The IP address of the client, such as 127.0.0.1. |
OptPlatform | The platform of the client. For more information on the value, see the parameter description of the OptPlatform in Third-Party Callback Overview: Callback Protocols. |
{
"CallbackCommand": "C2C.CallbackBeforeSendMsg", // The callback command that is run.
"From_Account": "jared", // The sender of the message.
"To_Account": "Jonh", // The recipient of the message.
"MsgSeq": 48374, // The sequence number of the message.
"MsgRandom": 2837546, // The random number of the message.
"MsgTime": 1557481126, // The timestamp indicating when the message was sent. Unit: seconds.
"MsgKey": "48374_2837546_1557481126", // The unique identifier of the message. It is used by RESTful APIs to recall a one-to-one chat message.
"MsgBody": [ // The body of the message. For more information, see the TIMMessage message object.
{
"MsgType": "TIMTextElem", // The text of the message.
"MsgContent": {}
"Text": "red packet"
}
}
]
}
Field | Type | Description |
---|---|---|
CallbackCommand | String | The callback command that is run. |
From_Account | String | The UserID of the message sender. |
To_Account | String | The UserID of the message recipient. |
MsgSeq | Integer | The message sequence number, and the unique UserID of a message. Group messages are sorted using MsgTime. The message with a larger MsgSeq value appears later. |
MsgRandom | Integer | The random number of the message. It is used to identify the message and the value is a random 32-bit unsigned integer. |
MsgTime | Integer | The message sending timestamp in seconds One-to-one messages sent in the same second are sorted using MsgTime. The message with a larger MsgSeq value appears later. |
MsgKey | String | The unique identifier of the message. It is used for Recalling a One-to-One Chat Message by using RESTful APIs. |
MsgBody | Array | The body of the message. For more information, see Message Format Description. |
In the following example, the user is allowed to chat and the IM backend does not modify the content of the to-be-delivered message.
{
"ActionStatus":"OK",
"ErrorInfo":"",
"ErrorCode": 0 // The value 0 indicates that chatting is allowed.
}
In the following example, the user is muted. In this case, the IM backend does not deliver the to-be-delivered message, but returns error code 20006
to the message sender.
{
"ActionStatus":"OK",
"ErrorInfo":"",
"ErrorCode": 1 // The value 1 indicates that the user is muted.
}
In the following example, the one-to-one chat message sent by the user is modified by adding custom information. In this case, the IM backend delivers the modified message. Based on this feature, the app backend can add special content such as the user level and title to the messages sent by users.
Example:
{
"ActionStatus":"OK",
"ErrorInfo":"",
"ErrorCode": 0, // The parameter must be set to 0 so that the IM backend can deliver the modified message normally.
"MsgBody": [ // The message modified by the app backend. If the app backend does not modify the message, the message sent by the user is used by default.
{
"MsgType": "TIMTextElem", // The text of the message.
"MsgContent": {}
"Text": "red packet"
}
},
{
"MsgType": "TIMCustomElem", // The custom information added to the message.
"MsgContent": {}
"Desc": " CustomElement.MemberLevel ", // The description of the message.
"Data": " LV1" // The data of the message.
}
}
]
}
Field | Type | Property | Description |
---|---|---|---|
ActionStatus | String | Required | The processing result of the request. OK: succeeded. FAIL: failed. |
ErrorCode | Integer | Required | The error code returned for the request. 0: not muted. 1: muted. If the business team wants to mute a user and sends ErrorCode and ErrorInfo to the client, ensure that the value of ErrorCode is set within the range of [120001, 130000]. |
ErrorInfo | String | Required | Detailed information on the error. |
MsgBody | Array | Optional | The message body modified by the app backend. The IM backend sends the modified message to the user’s friend in the one-to-one chat. For more information on the format, see Message Format Description. |
Was this page helpful?