Skip to main content

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

ParameterData TypeRequiredDescription
platformstringYesPlatform from which the message was sent. Valid values: iOS, Android, Web, PC, and Server.
senderstringYesMessage sender ID. Maximum length: 32 characters.
receiverstringYesMessage recipient ID. Maximum length: 32 characters.
channel_typeintYesConversation type. 1: private chat; 2: group chat; 3: chatroom.
msg_typestringYesMessage type identifier. Maximum length: 50 characters.
msg_contentstringYesMessage content. JSON format is recommended.
mention_info.mention_typestringNoMention type. mention_all: mention everyone; mention_someone: mention specified users; mention_all_someone: mention everyone and specified users.
mention_info.target_user_idsarrayNoIDs 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

ParameterData TypeRequiredDescription
resultstringYesCallback result. PASS: deliver the message; REJECT: reject the message; REPLACE: replace the message content; SILENT: reject the message without notifying the sender.
msg_typestringNoReplacement message type. This field applies when result is REPLACE.
msg_contentstringNoReplacement message content. This field applies when result is REPLACE.
mention_info.mention_typestringNoMention type. mention_all: mention everyone; mention_someone: mention specified users; mention_all_someone: mention everyone and specified users.
mention_info.target_user_idsarrayNoIDs of the users mentioned when specified users are mentioned.
custom_codeintNoCustom error code returned to the sending client when result is REJECT. If set to 0, the default IM error code is used.