圈组消息扩展

更新时间: 2023/07/21 06:56:54

消息扩展功能提供了圈组消息相关的扩展功能,包括会话消息回复(Message Threading)和快捷回复。

  • 会话消息回复和快捷回复均属于增值功能,需先在控制台开通后才能使用。
  • 圈组的消息扩展功能只能在圈组内使用,且相关接口/方法和 即时通讯 IM 的不一样。

会话消息回复

会话消息回复功能原理

会话消息回复指始于某条消息的一个消息回复主线(Thread)。

回复链示例见下图。

Thread消息.png

上图中:

  • 消息 A 是消息 B 的父消息,消息 B1 是消息 C 的父消息
  • 消息 C 是消息 B1 的子消息
  • 消息 A 是消息 B 和消息 C 的根消息
  • 消息 A、B、C 统称为 Threaded 消息
  • 一条 Thread 必须有一条父消息或至少一条子消息。如果一条消息既没有父消息,也没有子消息,则为普通消息。
  • 若未开通会话消息回复功能,回复时系统会自动将所发消息转换为一条普通消息。

Thread 中,除了根消息(如上图中的消息 A),其他消息都具有下表所示的属性。

会话消息回复在 [QChatMessage] 定义中追加了两个对象,replyRefer 作为 “回复消息”的引用 和 threadRefer 作为 “根消息” 引用 。

属性 说明
threadRefer.fromAccount 根消息的发送者账号
threadRefer.time 根消息的发送时间
threadRefer.msgIdServer 根消息在服务端(云信服务器)生成的消息 ID,该消息 ID 不一定存在(如开启易盾反垃圾的情况)
threadRefer.msgIdClient 根消息的客户端生成的消息 ID
replyRefer.fromAccount 父消息的发送者账号
replyRefer.time 父消息的发送时间
replyRefer.msgIdServer 父消息在服务端(云信服务器)生成的消息 ID,该消息 ID 不一定存在(如开启易盾反垃圾的情况)
replyRefer.msgIdClient 父消息的客户端生成的消息 ID

实现方法

发送回复消息

参照 QChatMsgServiceInterface-replyMessage

假设我们已经有了一条 "msgIdServer""6407677" 的消息,我们对它进行回复,示例如下:

jsconst message = await qchat.qchatMsg.replyMessage({
  "serverId": "1771109",
  "channelId": "1623869",
  "type": "text",
  "body": "天空海阔",
  "replyMessage": {
    "serverId": "1771109",
    "channelId": "1623869",
    "fromAccount": "cs1",
    "fromClientType": "Web",
    "fromDeviceId": "d95be95e20ee322643120ec3cdfedd34",
    "fromNick": "nibaba",
    "time": 1650613338241,
    "updateTime": 1650613338241,
    "type": "text",
    "body": "test111111",
    "msgIdClient": "4bef9fb59c09fc81b58e2c091592fca6",
    "msgIdServer": "6407677",
    "status": 0,
    "callbackExt": "callbackext123",
    "historyEnable": true,
    "pushEnable": true,
    "needBadge": true,
    "needPushNick": true,
    "notifyReason": "notifyAll",
    "routeEnable": true,
    "deliveryStatus": "success"
  }
})

注意:serverId 和 channelId 两条消息必须相同,因为不能在一个 server/channel 下回复别的 server/channel 的消息。

获取 Thread 的消息列表

参照 QChatMsgServiceInterface-getThreadMessages

假设我们需要查 "msgIdServer""6358905" 的相关 thread 消息列表,这条可以是根消息,也可以是子消息。示例如下:

jsawait qchat.qchatMsg.getThreadMessages({
  "message": {
    "fromAccount": "ctt1",
    "serverId": "1771109",
    "channelId": "1623869",
    "type": "text",
    "body": "点点滴滴",
    "fileInput": "external-file",
    "msgIdClient": "4a09be6680134b57d78ff4c10aa73265",
    "fromClientType": "Web",
    "fromDeviceId": "dc8221e74db03af6d0b52839665493c3",
    "fromNick": "ctt1",
    "time": 1649916251868,
    "updateTime": 1649916251868,
    "msgIdServer": "6358905",
    "status": 0,
    "callbackExt": "callbackext123",
    "historyEnable": true,
    "pushEnable": true,
    "needBadge": true,
    "needPushNick": true,
    "routeEnable": true,
    "deliveryStatus": "success"
  },
  "messageQueryOption": { "reverse": true }
})

查询某消息的父消息以及根消息

参照 QChatMsgServiceInterface-getReferMessages

示例如下:

jsconst result = await qchat.qchatMsg.getReferMessages({
  "message": {
    "serverId": "1771109",
    "channelId": "1623869",
    "fromAccount": "cs1",
    "fromClientType": "Web",
    "fromDeviceId": "16739a6f1a8efd489b2f85982ecd7edc",
    "fromNick": "大阴人212",
    "time": 1649767046449,
    "updateTime": 1649767046449,
    "type": "text",
    "body": "test123",
    "msgIdClient": "f790022bc768d08e6d3ee4b9d9ffb9b7",
    "msgIdServer": "6358275",
    "status": 0,
    "callbackExt": "callbackext123",
    "historyEnable": true,
    "pushEnable": true,
    "needBadge": true,
    "needPushNick": true,
    "notifyReason": "notifyAll",
    "routeEnable": true,
    "replyRefer": {
        "fromAccount": "ctt1",
        "time": 1649767022146,
        "msgIdServer": "6358274",
        "msgIdClient": "fb58529af074bf6ab130a6673322e584"
    },
    "threadRefer": {
        "fromAccount": "ctt1",
        "time": 1649767022146,
        "msgIdServer": "6358274",
        "msgIdClient": "fb58529af074bf6ab130a6673322e584"
    },
    "deliveryStatus": "success"
  },
  "referType": "all"
})

console.log(result.replyMessage, result.threadMessage)

根据消息 ID 批量查询消息

根据消息的 msgIdServer 查询历史消息,不分页,一次最多查询 100 条,参见 QChatMsgServiceInterface-getMessageHistoryByIds

示例如下:

jsconst messages = await qchat.qchatMsg.getMessageHistoryByIds({
  "serverId": "1771109",
  "channelId": "1623869",
  "messageReferList": [
    {
      "msgIdServer": "6128930",
      "time": 1648610230231
    }
  ]
})

快捷评论

快捷评论是一个操作功能,并非一种消息类型。评论内容并非一条消息,而是一个 number 类型,您需在应用上层指定评论内容与界面展示之间的联系。

实现方法

添加一条快捷评论

QChatMsgServiceInterface-addQuickComment

假设我们已经有了一条 "msgIdServer""6358276" 的消息,我们对他做一个快捷评论 type 为 1. 示例代码

jsawait qchat.qchatMsg.addQuickComment({
  "commentMessage": {
    "fromAccount": "ctt1",
    "serverId": "1771109",
    "channelId": "1623869",
    "type": "text",
    "body": "星空444444",
    "fileInput": "external-file",
    "msgIdClient": "0002bac24b2e2cac4c999d6ad77c392e",
    "fromClientType": "Web",
    "fromDeviceId": "c19b2572e36ed6d0f3c55d916b52371f",
    "fromNick": "ctt1",
    "time": 1649768937125,
    "updateTime": 1649768937125,
    "msgIdServer": "6358276",
    "status": 0,
    "callbackExt": "callbackext123",
    "historyEnable": true,
    "pushEnable": true,
    "needBadge": true,
    "needPushNick": true,
    "routeEnable": true,
    "deliveryStatus": "success"
  },
  "type": 1
})

至于 type 为 1 的快捷评论究竟有什么含义,需要开发者上层维护,它可以是一个简单的表情,见下文的 [快捷评论 UI 示例](#快捷评论 UI 示例).

删除快捷评论

参见:QChatMsgServiceInterface-removeQuickComment

仍旧拿上文的这条消息举例,现在移除自己给它的快捷评论,示例如下:

jsawait qchat.qchatMsg.removeQuickComment({
  "commentMessage": {
    "fromAccount": "ctt1",
    "serverId": "1771109",
    "channelId": "1623869",
    "type": "text",
    "body": "星空444444",
    "fileInput": "external-file",
    "msgIdClient": "0002bac24b2e2cac4c999d6ad77c392e",
    "fromClientType": "Web",
    "fromDeviceId": "c19b2572e36ed6d0f3c55d916b52371f",
    "fromNick": "ctt1",
    "time": 1649768937125,
    "updateTime": 1649768937125,
    "msgIdServer": "6358276",
    "status": 0,
    "callbackExt": "callbackext123",
    "historyEnable": true,
    "pushEnable": true,
    "needBadge": true,
    "needPushNick": true,
    "routeEnable": true,
    "deliveryStatus": "success"
  },
  "type": 1
})

查询快捷评论

参见 QChatMsgServiceInterface-getQuickComments

仍旧拿上文的这条消息举例,查询自己给它的快捷评论,示例如下:

jsconst result = await qchat.qchatMsg.removeQuickComment({
  "serverId": "1771109",
  "channelId": "1623869",
  "msgList": [{
    "fromAccount": "ctt1",
    "serverId": "1771109",
    "channelId": "1623869",
    "type": "text",
    "body": "星空444444",
    "fileInput": "external-file",
    "msgIdClient": "0002bac24b2e2cac4c999d6ad77c392e",
    "fromClientType": "Web",
    "fromDeviceId": "c19b2572e36ed6d0f3c55d916b52371f",
    "fromNick": "ctt1",
    "time": 1649768937125,
    "updateTime": 1649768937125,
    "msgIdServer": "6358276",
    "status": 0,
    "callbackExt": "callbackext123",
    "historyEnable": true,
    "pushEnable": true,
    "needBadge": true,
    "needPushNick": true,
    "routeEnable": true,
    "deliveryStatus": "success"
  }]
})

console.log(result["6358276"].totalCount)

返回的内容是 key 为 msgIdServer 的多个对象,内容包含这条消息的总评论数,每个快捷评论的详情等信息,参见 QChatMsgServiceInterface-QChatGetQuickCommentsResult

UI 示例

会话消息回复 UI 示例

会话消息回复的 UI 示例见下图。

Thread聊天.png

快捷评论 UI 示例

快捷评论的 UI 示例见下图。

快捷评论.png

此文档是否对你有帮助?
有帮助
去反馈
  • 会话消息回复
  • 会话消息回复功能原理
  • 实现方法
  • 发送回复消息
  • 获取 Thread 的消息列表
  • 查询某消息的父消息以及根消息
  • 根据消息 ID 批量查询消息
  • 快捷评论
  • 实现方法
  • 添加一条快捷评论
  • 删除快捷评论
  • 查询快捷评论
  • UI 示例
  • 会话消息回复 UI 示例
  • 快捷评论 UI 示例