IM 即时通讯
Web
产品介绍
简介
主要功能
产品优势
海外数据中心
IM平滑迁移方案
接口及业务限制
功能介绍
帐号集成与登录
基础消息功能
群组功能
聊天室功能
聊天室标签功能
多端登录与互踢策略
质量数据监控台
体验 Demo
下载 SDK 与 Demo 源码
更新日志
IM UIKit 更新日志
NIM SDK 开发版更新日志
NIM SDK 稳定版更新日志
快速开始
跑通 IM Demo 源码
实现 IM 文本消息收发(不含 UI)
含 UI 集成
什么是 IM UIKit
IM UIKit 功能概览
快速集成 IM UIKit
非React框架集成 IM UIKit
组件导入
初始化
全局上下文
登录相关
实现消息收发及界面自定义
集成会话列表界面
集成会话消息界面
集成用户资料组件
集成通讯录界面
集成搜索组件
非 React 框架自定义渲染
主题样式设置
语言设置
初始化(兼容 NIM SDK)
不含 UI 集成
集成 SDK
浏览器环境集成
Node.js集成
初始化与登录相关
初始化与登录 IM
IM 连接相关
多端登录与互踢
消息相关
消息概述
消息收发
消息配置选项
广播消息收发
消息已读回执
消息撤回
消息重发与转发
本地消息
通知消息
群通知消息
超大群通知消息
历史消息
最近会话
用户资料托管
好友关系托管
用户关系托管
在线状态订阅
群组功能
群组概述
群组管理
群成员管理
群消息管理
超大群功能
系统通知
系统通知概述
内置系统通知管理
内置系统通知未读数
自定义系统通知收发
开通聊天室功能
聊天室
反垃圾(内容审核)
域名高可用
融合存储方案
扩展功能
工具方法
最佳实践
聊天室重要消息投递
API参考
SDK API (Web)
IM UIKit Store API
状态码
IM 控制台指南
创建应用
注册 IM 账号
升级服务
开通聊天室功能
配置应用客户端标识
常见问题
FAQ
服务协议

圈组消息扩展

更新时间: 2022/12/21 15:55:40

消息扩展功能提供了圈组消息相关的扩展功能,包括会话消息回复(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" 的消息,我们对它进行回复,示例如下:

const 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 消息列表,这条可以是根消息,也可以是子消息。示例如下:

await 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

示例如下:

const 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

示例如下:

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

快捷评论

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

实现方法

添加一条快捷评论

QChatMsgServiceInterface-addQuickComment

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

await 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

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

await 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

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

const 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 示例