跳到主要内容

修改消息内容的回调

功能说明

App 业务服务端可以通过该回调修改消息内容,如:不合规内容、敏感词汇的修改替换。

注意事项

  • 为启用回调,必须配置回调 URL,并开启本条回调协议对应的开关。配置方法详见 回调说明 文档。
  • 回调的方向是 OpenIMServer 向 App 后台发起 HTTP/HTTPS POST 请求。
  • APP 业务服务端需在超时时间内响应此请求。

可能触发该回调的场景

  • App 用户通过客户端发送消息
  • App 用户通过 REST API 发送消息
  • App 用户通过客户端发送群消息。
  • App 管理员通过 REST API 发送群消息。

回调发生时机

  • OpenIMServer 把群消息下发给群成员之前。

接口说明

请求 URL 示例

以下示例中 App 配置的回调 URL 为 http://www.example.com/callbackCommand?contenttype=json

http://www.example.com/callbackMsgModifyCommandCommand?contenttype=json

请求参数说明

参数说明
http请求协议为 HTTP,请求方式为 POST
www.example.comconfigy.yaml 中的 callback.url 字段,域名或主机名
CallbackCommand此处为:callbackMsgModifyCommandCommand
contenttype固定值为:JSON
header名示例值选填类型说明
operationID1646445464564必填stringoperationID用于全局链路追踪

请求包示例

{
"sendID": "sender123",
"callbackCommand": "callbackMsgModifyCommandCommand",
"serverMsgID": "serverMsg123",
"clientMsgID": "clientMsg123",
"senderPlatformID": 1,
"senderNickname": "Sender",
"sessionType": 1,
"msgFrom": 1,
"contentType": 1,
"status": 1,
"createTime": 1673048592000,
"content": "Hello, World!",
"seq": 123,
"atUserList": ["user123", "user456"],
"faceURL": "http://example.com/sender_face.png",
"ex": "Extra data"
}

请求包字段说明

对象类型描述
sendIDstring发送者的唯一标识符
callbackCommandstring回调命令,这里是消息修改命令回调
serverMsgIDstring服务端生成的消息ID
clientMsgIDstring客户端生成的消息ID
senderPlatformIDint32发送者的平台ID
senderNicknamestring发送者的昵称
sessionTypeint32会话类型,表示单聊或群聊
msgFromint32消息来源,表示消息是发送还是接收
contentTypeint32消息的内容类型
statusint32消息的状态
createTimeint64消息创建的时间戳(毫秒)
contentstring消息的内容
sequint32消息的序号
atUserList[]string群成员ID列表
faceURLstring发送者的头像URL
exstring额外的数据字段

应答包示例

允许修改

允许对消息进行修改。

{
"actionCode": 0,
"errCode": 0,
"errMsg": "Success",
"errDlt": "",
"nextCode": 0,
"content": "Modified content",
"recvID": "receiver123",
"groupID": "group123",
"clientMsgID": "clientMsg456",
"serverMsgID": "serverMsg456",
"senderPlatformID": 1,
"senderNickname": "ModifiedSender",
"senderFaceURL": "http://example.com/modified_sender_face.png",
"sessionType": 1,
"msgFrom": 1,
"contentType": 1,
"status": 1,
"options": {
"option1": true,
"option2": false
},
"offlinePushInfo": {
"title": "Modified Notification",
"content": "Modified Content",
"pushFlag": 1,
"sound": "default",
"badge": 1
},
"atUserIDList": ["user789", "user101112"],
"msgDataList": [65, 66, 67],
"attachedInfo": "Modified Info",
"ex": "Modified Extra data"
}

应答包字段说明

字段说明
actionCode0表示业务系统的回调是否正确执行。0表示操作成功。
errCode5001表示自定义错误码,范围在5000-9999之间。在 actionCode 不等于0时设置;在 nextCode 等于1时设置。
errMsg"An error message"自定义错误码对应的简单错误信息。
errDlt"Detailed error information"自定义错误码对应的详细错误信息。
nextCode1下一步执行指令,1表示拒绝继续执行,actionCode 等于0时设置。
contentstring修改后的消息内容。
recvIDstring接收消息的用户ID。
groupIDstring群组的唯一标识符。
clientMsgIDstring客户端生成的消息ID。
serverMsgIDstring服务端生成的消息ID。
senderPlatformIDint32发送者的平台ID。
senderNicknamestring发送者的昵称。
senderFaceURLstring发送者的头像URL。
sessionTypeint32会话类型。
msgFromint32消息来源。
contentTypeint32消息的内容类型。
statusint32消息的状态。
optionsmap[string]bool修改后的消息选项。
offlinePushInfoOfflinePushInfo修改后的离线推送信息。
atUserIDList[]string群成员ID列表。
msgDataList[]byte修改后的消息数据列表。
attachedInfostring修改后的附加信息。
exstring修改后的额外的数据字段。