浏览 平台 API
服务端 API

消息写入前

复制

在消息最终写入前调整允许修改的消息字段。

触发时机

项目说明
类型前置回调
配置项beforeMsgModify
回调命令callbackBeforeMsgModifyCommand

HTTP 请求

POST {WEBHOOK_ADDRESS}/callbackBeforeMsgModifyCommand
Content-Type: application/json
operationID: {OPERATION_ID}
{
  "sendID": "user_001",
  "recvID": "user_001",
  "callbackCommand": "callbackBeforeMsgModifyCommand",
  "serverMsgID": "server_msg_001",
  "clientMsgID": "client_msg_001",
  "operationID": "operation_001",
  "senderPlatformID": 1,
  "senderNickname": "user_001",
  "sessionType": 1,
  "msgFrom": 1,
  "contentType": 1,
  "status": 1,
  "sendTime": 1719800000000,
  "createTime": 1719800000000,
  "content": "{\"text\":\"hello\"}",
  "seq": 1,
  "atUserList": ["user_001"],
  "faceURL": "https://example.com/avatar.png",
  "ex": "",
  "keyVersion": 1
}

请求体参数

参数名是否必填类型说明
sendIDstring消息发送者用户 ID。
recvID 商业版string消息接收者用户 ID;单聊时为对端用户 ID。
callbackCommandstring回调命令,值与当前页面的回调命令一致。
serverMsgIDstringOpenIM 服务端消息 ID。
clientMsgIDstring客户端消息 ID。
operationIDstringOpenIM 操作的链路追踪 ID。
senderPlatformIDint发送端平台 ID,参见用户模块的 PlatformID
senderNicknamestring发送者昵称。
sessionTypeint会话类型,参见会话模块的 ConversationType
msgFromintmsgFrom 字段。
contentTypeint消息内容类型,参见消息内容类型
statusintstatus 字段。
sendTimeintsendTime 字段。
createTimeintcreateTime 字段。
contentstring消息内容;通常是与消息类型对应的 JSON 字符串。
seqint消息或连接序列号。
atUserListstring[]被 @ 的用户 ID 列表。
faceURLstring头像地址。
exstring业务扩展字段。
keyVersion 商业版int消息加密密钥版本号。

响应

业务服务端应返回 HTTP 成功状态和 JSON 响应体。

{
  "actionCode": 0,
  "errCode": 0,
  "errMsg": "",
  "errDlt": "",
  "nextCode": 0,
  "content": "{\"text\":\"hello\"}",
  "recvID": "user_001",
  "groupID": "group_001",
  "clientMsgID": "client_msg_001",
  "serverMsgID": "server_msg_001",
  "senderPlatformID": 1,
  "senderNickname": "user_001",
  "senderFaceURL": "user_001",
  "sessionType": 1,
  "msgFrom": 1,
  "contentType": 1,
  "status": 1,
  "options": {},
  "offlinePushInfo": {},
  "atUserIDList": ["user_001"],
  "msgDataList": [{}],
  "attachedInfo": "",
  "ex": ""
}

响应参数

参数名类型说明
actionCodeint处理状态,参见Webhooks 概述的 CallbackAction
errCodeint业务错误码;拒绝前置操作时返回业务约定的非零错误码。
errMsgstring错误简要信息。
errDltstring错误详细信息。
nextCodeint处理下一步,参见Webhooks 概述的 CallbackNextCode
contentstring消息内容;通常是与消息类型对应的 JSON 字符串。
recvIDstring消息接收者用户 ID;单聊时为对端用户 ID。
groupIDstring群组 ID。
clientMsgIDstring客户端消息 ID。
serverMsgIDstringOpenIM 服务端消息 ID。
senderPlatformIDint发送端平台 ID,参见用户模块的 PlatformID
senderNicknamestring发送者昵称。
senderFaceURLstring发送者头像地址。
sessionTypeint会话类型,参见会话模块的 ConversationType
msgFromintmsgFrom 字段。
contentTypeint消息内容类型,参见消息内容类型
statusintstatus 字段。
optionsobject消息发送选项。
offlinePushInfoobject离线推送配置。
atUserIDListstring[]被 @ 的用户 ID 列表。
msgDataListobject[]msgDataList 字段。
attachedInfostring附加信息。
exstring业务扩展字段。

处理规则

  • OpenIM 同步等待业务服务端响应。
  • 返回 nextCode: 0 时继续原流程;返回 nextCode: 1 时,OpenIM 使用响应中的错误信息终止本次操作。
  • 请求失败或超时后的行为由该回调的 failedContinue 配置决定。
  • 响应中的业务字段仅在对应字段存在时覆盖 OpenIM 即将处理的数据。

相关页面