Overview
When the IM Server receives a request to send a message, it can call your application server before distributing the message. Your application server determines whether the message should be delivered. This callback can be used for scenarios such as content moderation and access control.
Request
Webhook authentication: Add authentication headers to the request. See Authentication.
Callback response: Your application server must respond with HTTP status code 200 and specify whether the message should be delivered. See the response parameters below.
Execution mechanism: The callback gives your application server an opportunity to intervene before the message is distributed. Your server's response time directly affects message-processing latency. Messages sent through the Server API do not trigger this callback.
Request Parameters
| Parameter | Data Type | Required | Description | |
|---|---|---|---|---|
| platform | string | Yes | Platform from which the message was sent. Valid values: iOS, Android, Web, PC, and Server. | |
| sender | string | Yes | Message sender ID. Maximum length: 32 characters. | |
| receiver | string | Yes | Message recipient ID. Maximum length: 32 characters. | |
| channel_type | int | Yes | Conversation type. 1: private chat; 2: group chat; 3: chatroom. | |
| msg_type | string | Yes | Message type identifier. Maximum length: 50 characters. | |
| msg_content | string | Yes | Message content. JSON format is recommended. | |
| mention_info.mention_type | string | No | Mention type. mention_all: mention everyone; mention_someone: mention specified users; mention_all_someone: mention everyone and specified users. | |
| mention_info.target_user_ids | array | No | IDs of the users mentioned when specified users are mentioned. Each user ID can contain up to 32 characters. |
Request Example
POST /message/callback HTTP/1.1
appkey: appkey
signature: 2e639ae3600a4sdff61fb88b76f485b
nonce: nonce
timestamp: 1672568121910
Content-Type: application/json
{
"platform":"iOS",// iOS/Android/Web/PC/Server
"sender": "userid1", //senduid
"receiver": "userid2", //receiveuid
"channel_type": 1, //1:private 2:group 3:chatroom
"msg_type": "text",
"msg_content": "Hello, world!",
"mention_info":{
"mention_type":"mention_someone",
"target_user_ids":["userid1","userid2"]
}
}
Response Example
{
"result":"PASS",//REJECT, REPLACE, SILENT
"msg_type":"jg:text",
"msg_content":"{\"content\":\"hello world!\"}",
"mention_info":{
"mention_type":"mention_someone",
"target_user_ids":["userid1","userid2"]
},
"custom_code":132
}
Response Parameters
| Parameter | Data Type | Required | Description | |
|---|---|---|---|---|
| result | string | Yes | Callback result. PASS: deliver the message; REJECT: reject the message; REPLACE: replace the message content; SILENT: reject the message without notifying the sender. | |
| msg_type | string | No | Replacement message type. This field applies when result is REPLACE. | |
| msg_content | string | No | Replacement message content. This field applies when result is REPLACE. | |
| mention_info.mention_type | string | No | Mention type. mention_all: mention everyone; mention_someone: mention specified users; mention_all_someone: mention everyone and specified users. | |
| mention_info.target_user_ids | array | No | IDs of the users mentioned when specified users are mentioned. | |
| custom_code | int | No | Custom error code returned to the sending client when result is REJECT. If set to 0, the default IM error code is used. |