SDK

SDK

即时通信 IM SDK 基本概念:

基本概念 说明
Message(消息) IM SDK 中 Message 表示要发送给对方的内容,消息包括若干属性,例如自己是否为发送者,发送人账号以及消息产生时间等。
Conversation(会话) IM SDK 中 Conversation 分为两种:
  • C2C(Client to Client)会话,表示单聊情况,自己与对方建立的对话。
  • GROUP(群)会话,表示群聊情况下群内成员组成的会话。
  • Profile(资料) IM SDK 中 Profile 描述个人的常用基本信息,例如昵称、性别、个性签名以及头像地址等。
    Friend(好友) IM SDK 中 Friend 描述好友的常用基本信息,例如备注、分组等。
    FriendApplication(好友申请) IM SDK 中 FriendApplication 描述好友申请的常用基本信息,例如加好友来源、备注等。
    FriendGroup(好友分组) IM SDK 中 FriendGroup 描述好友分组的常用基本信息,例如分组名、分组成员等。
    Group(群组) IM SDK 中 Group 表示一个支持多人聊天的通信系统,支持好友工作群(Work)、陌生人社交群(Public)、临时会议群(Meeting)和直播群(AVChatRoom)
    GroupMember(群成员) IM SDK 中 GroupMember 描述群内成员的常用基本信息,例如 ID、昵称、群内身份以及入群时间等。
    信令(Signaling) IM SDK 中 Signaling 描述信令的常用基本信息。例如 ID、邀请者 ID、被邀请人 ID 列表,操作类型、超时时间等。
    群提示消息 当有用户被邀请加入群组或被移出群组等事件发生时,群内会产生提示消息,接入侧可以根据实际需求展示给群组用户或忽略。
    群提示消息有多种类型,详细描述请参见 Message.GroupTipPayload
    群系统通知消息 当有用户申请加群等事件发生时,管理员会收到申请加群等系统消息。管理员同意或拒绝加群申请,IM SDK 会通过群系统通知消息将申请加群等相应消息发送给接入侧,由接入侧展示给用户。
    群系统通知消息有多种类型,详细描述请参见 Message.GroupSystemNoticePayload
    消息上屏 用户单击发送后,事先输入的文字或选择的图片等信息显示在用户电脑屏幕或手机屏幕上的过程。

    支持的平台:

    • IM SDK 支持 IE 9+、Chrome、微信、手机QQ、QQ 浏览器、FireFox、Opera 和 Safari。

    集成 SDK

    集成方式 示例
    NPM 集成 npm i @tencentcloud/chat --save
    // 发送图片、文件等消息需要的上传插件
    npm install tim-upload-plugin --save
    Example
    import TencentCloudChat from '@tencentcloud/chat';
    import TIMUploadPlugin from 'tim-upload-plugin';
    
    // 创建 SDK 实例,TencentCloudChat.create() 方法对于同一个 SDKAppID 只会返回同一份实例
    let options = {
      SDKAppID: 0 // 接入时需要将0替换为您的即时通信应用的 SDKAppID
    };
    let chat = TencentCloudChat.create(options); // SDK 实例通常用 chat 表示
    // 设置 SDK 日志输出级别,详细分级请参见 setLogLevel 接口的说明
    chat.setLogLevel(0); // 普通级别,日志量较多,接入时建议使用
    // chat.setLogLevel(1); // release级别,SDK 输出关键信息,生产环境时建议使用
    
    // 注册腾讯云即时通信 IM 上传插件,即时通信 IM SDK 发送图片、语音、视频、文件等消息需要使用上传插件,将文件上传到腾讯云对象存储
    chat.registerPlugin({'tim-upload-plugin': TIMUploadPlugin});
    
    // 如果您使用 uni-app 开发 app,并有推送需求,请使用 [TIMPush](https://cloud.tencent.com/document/product/269/103522)
    
    // 监听事件,如:
    chat.on(TencentCloudChat.EVENT.SDK_READY, function(event) {
      // 收到离线消息和会话列表同步完毕通知,接入侧可以调用 sendMessage 等需要鉴权的接口
      // event.name - TencentCloudChat.EVENT.SDK_READY
    });
    
    chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, function(event) {
      // 收到推送的单聊、群聊、群提示、群系统通知的新消息,可通过遍历 event.data 获取消息列表数据并渲染到页面
      // event.name - TencentCloudChat.EVENT.MESSAGE_RECEIVED
      // event.data - 存储 Message 对象的数组 - [Message]
    });
    
    chat.on(TencentCloudChat.EVENT.MESSAGE_MODIFIED, function(event) {
      // 收到消息被第三方回调修改的通知,消息发送方可通过遍历 event.data 获取消息列表数据并更新页面上同 ID 消息的内容
      // event.name - TencentCloudChat.EVENT.MESSAGE_MODIFIED
      // event.data - 存储被第三方回调修改过的 Message 对象的数组 - [Message]
    });
    
    chat.on(TencentCloudChat.EVENT.MESSAGE_REVOKED, function(event) {
      // 收到消息被撤回的通知。
      // event.name - TencentCloudChat.EVENT.MESSAGE_REVOKED
      // event.data - 存储 Message 对象的数组 - [Message] - 每个 Message 对象的 isRevoked 属性值为 true
    });
    
    chat.on(TencentCloudChat.EVENT.MESSAGE_READ_BY_PEER, function(event) {
      // SDK 收到对端已读消息的通知,即已读回执。
      // event.name - TencentCloudChat.EVENT.MESSAGE_READ_BY_PEER
      // event.data - event.data - 存储 Message 对象的数组 - [Message] - 每个 Message 对象的 isPeerRead 属性值为 true
    });
    
    chat.on(TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED, function(event) {
      // 收到会话列表更新通知,可通过遍历 event.data 获取会话列表数据并渲染到页面
      // event.name - TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED
      // event.data - 存储 Conversation 对象的数组 - [Conversation]
    });
    
    chat.on(TencentCloudChat.EVENT.GROUP_LIST_UPDATED, function(event) {
      // 收到群组列表更新通知,可通过遍历 event.data 获取群组列表数据并渲染到页面
      // event.name - TencentCloudChat.EVENT.GROUP_LIST_UPDATED
      // event.data - 存储 Group 对象的数组 - [Group]
    });
    
    chat.on(TencentCloudChat.EVENT.PROFILE_UPDATED, function(event) {
      // 收到自己或好友的资料变更通知
      // event.name - TencentCloudChat.EVENT.PROFILE_UPDATED
      // event.data - 存储 Profile 对象的数组 - [Profile]
    });
    
    chat.on(TencentCloudChat.EVENT.BLACKLIST_UPDATED, function(event) {
      // 收到黑名单列表更新通知
      // event.name - TencentCloudChat.EVENT.BLACKLIST_UPDATED
      // event.data - 存储 userID 的数组 - [userID]
    });
    
    chat.on(TencentCloudChat.EVENT.SDK_NOT_READY, function(event) {
      // 收到 SDK 进入 not ready 状态通知,此时 SDK 无法正常工作
      // event.name - TencentCloudChat.EVENT.SDK_NOT_READY
    });
    
    chat.on(TencentCloudChat.EVENT.KICKED_OUT, function(event) {
      // 收到被踢下线通知
      // event.name - TencentCloudChat.EVENT.KICKED_OUT
      // event.data.type - 被踢下线的原因,例如 :
      //   - TencentCloudChat.TYPES.KICKED_OUT_MULT_ACCOUNT 多实例登录被踢
      //   - TencentCloudChat.TYPES.KICKED_OUT_MULT_DEVICE 多终端登录被踢
      //   - TencentCloudChat.TYPES.KICKED_OUT_USERSIG_EXPIRED 签名过期被踢
      //   - TencentCloudChat.TYPES.KICKED_OUT_REST_API(REST API kick 接口踢出。)
    });
    
    chat.on(TencentCloudChat.EVENT.NET_STATE_CHANGE, function(event) {
      // 网络状态发生改变
      // event.name - TencentCloudChat.EVENT.NET_STATE_CHANGE
      // event.data.state 当前网络状态,枚举值及说明如下:
      //   - TencentCloudChat.TYPES.NET_STATE_CONNECTED - 已接入网络
      //   - TencentCloudChat.TYPES.NET_STATE_CONNECTING - 连接中。很可能遇到网络抖动,SDK 在重试。接入侧可根据此状态提示“当前网络不稳定”或“连接中”
      //   - TencentCloudChat.TYPES.NET_STATE_DISCONNECTED - 未接入网络。接入侧可根据此状态提示“当前网络不可用”。SDK 仍会继续重试,若用户网络恢复,SDK 会自动同步消息
    });
    
    chat.on(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, function(event) {
      // 收到好友列表更新通知
      // event.name - TencentCloudChat.EVENT.FRIEND_LIST_UPDATED
      // event.data - 存储 Friend 对象的数组 - [Friend]
    });
    
    chat.on(TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED, function(event) {
      // 收到好友申请列表更新通知
      // event.name - TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED
      // friendApplicationList - 好友申请列表 - [FriendApplication]
      // unreadCount - 好友申请的未读数
      // const { friendApplicationList, unreadCount } = event.data;
      // 发送给我的好友申请(即别人申请加我为好友)
      // const applicationSentToMe = friendApplicationList.filter((friendApplication) => friendApplication.type === TencentCloudChat.TYPES.SNS_APPLICATION_SENT_TO_ME);
      // 我发送出去的好友申请(即我申请加别人为好友)
      // const applicationSentByMe = friendApplicationList.filter((friendApplication) => friendApplication.type === TencentCloudChat.TYPES.SNS_APPLICATION_SENT_BY_ME);
    });
    
    chat.on(TencentCloudChat.EVENT.FRIEND_GROUP_LIST_UPDATED, function(event) {
      // 收到好友分组列表更新通知
      // event.name - TencentCloudChat.EVENT.FRIEND_GROUP_LIST_UPDATED
      // event.data - 存储 FriendGroup 对象的数组 - [FriendGroup]
    });
    
    // 开始登录
    chat.login({userID: 'your userID', userSig: 'your userSig'});

    Methods

    login(options) → {Promise}

    使用用户 ID(userID)和签名串(userSig)登录即时通信 IM,登录流程有若干个异步执行的步骤,使用返回的 Promise 对象处理登录成功或失败。

    注意1:登录成功,需等待 SDK 处于 ready 状态后(监听事件 TencentCloudChat.EVENT.SDK_READY)才能调用 sendMessage 等需要鉴权的接口。
    注意2:默认情况下,不支持多实例登录,即如果此账号已在其他页面登录,若继续在当前页面登录成功,有可能会将其他页面踢下线。用户被踢下线时会触发事件TencentCloudChat.EVENT.KICKED_OUT,用户可在监听到事件后做相应处理。
    注意3:如需支持多实例登录(允许在多个网页中同时登录同一账号),请到 即时通信 IM 控制台,找到相应 SDKAppID,【应用配置】>【功能配置】>【登录与消息】>【Web端可同时在线个数】配置实例个数。配置将在5分钟内生效。
    注意4:小程序、小游戏和 uni-app(即使打包成 native app) 平台集成,登录后都算作 web 实例。
    注意5:如果此接口返回错误码 60020,意味着您未购买套餐包,或套餐包已过期,或购买的套餐包正在配置中暂未生效。请登录 即时通信 IM 购买页面 重新购买套餐包。购买后,将在5分钟后生效。
    注意6:如果在小程序平台此接口返回错误码 2801,请您检查小程序受信域名 配置

    Example
    let promise = chat.login({userID: 'your userID', userSig: 'your userSig'});
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 登录成功
      if (imResponse.data.repeatLogin === true) {
        // 标识账号已登录,本次登录操作为重复登录。
        console.log(imResponse.data.errorInfo);
      }
    }).catch(function(imError) {
      console.warn('login error:', imError); // 登录失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    登录配置

    Properties
    Name Type Description
    userID String required

    用户 ID

    userSig String required

    用户登录即时通信 IM 的密码,其本质是对 UserID 等信息加密后得到的密文。
    具体生成方法请参见生成 UserSig

    Returns:
    Type
    Promise

    logout() → {Promise}

    登出即时通信 IM,通常在切换账号的时候调用,清除登录态以及内存中的所有数据。

    注意1:调用此接口的实例会发布 SDK_NOT_READY 事件,此时该实例下线,无法收、发消息。
    注意2:如果您在即时通信 IM 控制台配置的“Web端实例同时在线个数”大于 1,且同一账号登录了a1a2两个实例(含小程序端),当执行a1.logout()后,a1会下线,无法收、发消息。而a2实例不会受影响。
    注意3:多实例被踢:基于第 2 点,如果“Web端实例同时在线个数”配置为 2,且您的某一账号已经登录了 a1a2两个实例,当使用此账号成功登录第三个实例a3时,a1a2中的一个实例会被踢下线(通常是最先处在登录态的实例会触发),这种情况称之为**“多实例被踢”**。假设a1实例被踢下线,a1实例内部会执行登出流程,然后抛出KICKED_OUT事件,接入侧可以监听此事件,并在触发时跳转到登录页。此时a1实例下线,而a2a3实例可以正常运行。

    Example
    let promise = chat.logout();
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 登出成功
    }).catch(function(imError) {
      console.warn('logout error:', imError);
    });
    Returns:
    Type
    Promise

    getLoginUser() → {String}

    获取登录用户信息。

    注意:v3.2.1 起支持。

    Example
    const userID = chat.getLoginUser();
    Returns:

    已登录返回登录用户的 userID,未登录返回 ''。

    Type
    String

    isReady() → {Boolean}

    SDK 是否 ready。SDK ready 后,开发者可调用 SDK 发送消息等 API,使用 SDK 的各项功能。
    开发者也可以监听:

    Example
    let isReady = chat.isReady();
    Returns:
    Type
    Boolean

    destroy() → {Promise}

    销毁 SDK 实例。SDK 会先 logout,然后断开 WebSocket 长连接,并释放资源

    Example
    let promise = chat.destroy();
    Returns:
    Type
    Promise

    on(eventName, handler, contextopt)

    监听事件。

    注意:请在调用 login 接口前调用此接口监听事件,避免漏掉 SDK 派发的事件。

    Example
    let onMessageReceived = function(event) {
      // 收到推送的单聊、群聊、群提示、群系统通知的新消息,可通过遍历 event.data 获取消息列表数据并渲染到页面
      // event.name - TencentCloudChat.EVENT.MESSAGE_RECEIVED
      // event.data - 存储 Message 对象的数组 - [Message]
    };
    chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived);
    Parameters:
    Name Type Description
    eventName String required

    事件名称。所有的事件名称都存放在 TencentCloudChat.EVENT 变量中,如需要查看可以使用 console.log(TencentCloudChat.EVENT) 把所有的事件显示出来。事件列表

    handler function required

    处理事件的方法,当事件触发时,会调用此handler进行处理。

    context *

    期望 handler 执行时的上下文

    off(eventName, handler, contextopt, onceopt)

    取消监听事件。

    Example
    let onMessageReceived = function(event) {
      // 收到推送的单聊、群聊、群提示、群系统通知的新消息,可通过遍历 event.data 获取消息列表数据并渲染到页面
      // event.name - TencentCloudChat.EVENT.MESSAGE_RECEIVED
      // event.data - 存储 Message 对象的数组 - [Message]
    };
    chat.off(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived);
    Parameters:
    Name Type Description
    eventName String required

    事件名称。所有的事件名称都存放在 TencentCloudChat.EVENT 变量中,如需要查看可以使用 console.log(TencentCloudChat.EVENT) 把所有的事件显示出来。事件列表

    handler function required

    处理事件的方法,当事件触发时,会调用此handler进行处理。

    context *

    期望 handler 执行时的上下文

    once Boolean

    是否只解绑一次

    registerPlugin(options)

    注册插件。

    注意1:发送图片、语音、视频、文件等消息需要使用上传插件 tim-upload-plugin,将文件上传到腾讯云对象存储。
    注意2:uni-app 打包终端应用,推送插件请使用 TIMPush
    注意3:推送插件的配置文件可以在IM控制台 > 推送管理 > 接入设置进行下载 。

    Examples
    // 小程序端使用 tim-upload-plugin,在小程序管理后台增加 uploadFile 域名配置 https://cos.ap-shanghai.myqcloud.com,增加 downloadFile 域名配置 https://cos.ap-shanghai.myqcloud.com
    chat.registerPlugin({'tim-upload-plugin': TIMUploadPlugin});
    // 注册推送插件
    // 推送插件(TIMPush)为您提供稳定、及时、多样化的推送服务。推送插件支持普通消息推送和全员/标签推送,提供完整的推送生命周期查询、数据统计、问题排查服务。
    // 如果您有聊天、音视频通话、信令等场景,需要离线场景也能及时触达,可以关注普通消息推送功能。
    // 如果您有营销广告、通知、新闻资讯等需要推送给所有用户或指定群体,可以关注全员/标签推送功能。
    // 离线推送厂商支持小米、华为、荣耀、OPPO、vivo、魅族、APNs,包含各厂商子品牌如一加、realme、iQOO 等,境外支持 Google FCM。
    // 推送管理控制台为您提供全链路排查工具、推送记录和各类型指标统计数据,方便您查看推送触达率、点击率和转化率等各类指标。
    // 请注意!应合规要求,在用户同意隐私协议的前提下,登录成功后 SDK 会通过推送插件获取推送 token,并将推送 token 传递至后台(若获取 token 失败则会导致离线推送无法正常使用)
    import TIMPushAndroidConfig from "./timpush-configs.json"; // IM控制台 > 推送管理 > 接入设置下载配置文件
    const TIMPush = uni.requireNativePlugin("TencentCloud-TIMPush");
    
    chat.registerPlugin({
      'tim-push': TIMPush,
      'pushConfig': {
         androidConfig: TIMPushAndroidConfig,
         iOSConfig: {
           iOSBusinessID: ''
         }
      }
    });
    Parameters:
    Name Type Description
    options Object required

    插件配置

    Properties
    Name Type Description
    value Class required

    插件类

    pushConfig Object required

    推送插件配置

    setLogLevel(level)

    设置日志级别,低于 level 的日志将不会输出。

    Example
    chat.setLogLevel(0);
    Parameters:
    Name Type Description
    level Number required

    日志级别

    • 0 普通级别,日志量较多,接入时建议使用
    • 1 release级别,SDK 输出关键信息,生产环境时建议使用
    • 2 告警级别,SDK 只输出告警和错误级别的日志
    • 3 错误级别,SDK 只输出错误级别的日志
    • 4 无日志级别,SDK 将不打印任何日志

    createTextMessage(options) → {Message}

    创建文本消息的接口,此接口返回一个消息实例,可以在需要发送文本消息时调用 发送消息 接口发送消息。

    注意1:创建话题消息时 to 是话题 ID, conversationType 是 TencentCloudChat.TYPES.CONV_GROUP
    注意2:创建群消息时支持指定消息接收者(可实现群内定向消息功能,即只有被指定的群成员才会收到消息)。
    注意3:v3.3.0起,支持自定义消息审核策略,请参考 customModerationConfigurationID 参数的描述。

    Examples
    // 发送文本消息,Web 端与小程序端相同
    // 1. 创建消息实例,接口返回的实例可以上屏
    let message = chat.createTextMessage({
      to: 'user1',
      conversationType: TencentCloudChat.TYPES.CONV_C2C,
      // 消息优先级,用于群聊。如果某个群的消息超过了频率限制,后台会优先下发高优先级的消息,详细请参考:https://cloud.tencent.com/document/product/269/3663#.E6.B6.88.E6.81.AF.E4.BC.98.E5.85.88.E7.BA.A7.E4.B8.8E.E9.A2.91.E7.8E.87.E6.8E.A7.E5.88.B6)
      // 支持的枚举值:TencentCloudChat.TYPES.MSG_PRIORITY_HIGH, TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL(默认), TencentCloudChat.TYPES.MSG_PRIORITY_LOW, TencentCloudChat.TYPES.MSG_PRIORITY_LOWEST
      // priority: TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL,
      payload: {
        text: 'Hello world!'
      },
      // 支持C2C消息已读回执功能,如果您发消息需要已读回执,需购买旗舰版套餐,并且创建消息时将 needReadReceipt 设置为 true
      needReadReceipt: true
      // 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
      // cloudCustomData: 'your cloud custom data'
    });
    // 2. 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    // 发送群消息
    let message = chat.createTextMessage({
      to: 'test',
      conversationType: TencentCloudChat.TYPES.CONV_GROUP,
      payload: {
        text: 'Hello world!'
      },
      // 支持群消息已读回执功能,如果您发消息需要已读回执,需购买旗舰版套餐,并且创建消息时将 needReadReceipt 设置为 true
      needReadReceipt: true
    });
    // 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    // 向社群(不支持话题)发消息
    let message = chat.createTextMessage({
      to: '@TGS#_@TGS#cWWFWHIM62CL', // 社群 ID
      conversationType: TencentCloudChat.TYPES.CONV_GROUP,
      payload: {
        text: 'Hello world!'
      },
      // 如果您发消息需要已读回执,需购买旗舰版套餐,并且创建消息时将 needReadReceipt 设置为 true
      needReadReceipt: true
    });
    // 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    // 向话题(Topic)发消息
    let message = chat.createTextMessage({
      to: '@TGS#_@TGS#cWWFWHIM62CL@TOPIC#_@TOPIC#cXWFWHIM62CR', // 话题 ID
      conversationType: TencentCloudChat.TYPES.CONV_GROUP,
      payload: {
        text: 'Hello world!'
      },
    });
    // 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    // 发送群定向消息
    // 注意:群定向消息不计入会话未读,receiverList 最大支持50个接收者。
    let message = chat.createTextMessage({
      to: 'test',
      conversationType: TencentCloudChat.TYPES.CONV_GROUP,
      payload: {
        text: 'Hello world!'
      },
      // 如果您需要发群定向消息,需购买旗舰版套餐,并且创建消息时通过 receiverList 指定消息接收者
      receiverList: ['user0', 'user1']
    });
    // 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    // 发送支持消息扩展的群消息
    let message = chat.createTextMessage({
      to: 'test',
      conversationType: TencentCloudChat.TYPES.CONV_GROUP,
      payload: {
        text: 'Hello world!'
      },
      // 如果您发消息需要支持扩展,需购买旗舰版套餐,并且创建消息时将 isSupportExtension 设置为 true
      isSupportExtension: true
    });
    // 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    // 自定义消息审核策略
    let message = chat.createTextMessage({
      to: 'test',
      conversationType: TencentCloudChat.TYPES.CONV_GROUP,
      payload: {
        text: 'Hello world!'
      },
      customModerationConfigurationID: 'Custom11',
    });
    // 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    to String required

    消息接收方的 userID、groupID 或 topicID

    conversationType String required

    会话类型,取值TencentCloudChat.TYPES.CONV_C2C(端到端会话) 或 TencentCloudChat.TYPES.CONV_GROUP(群组会话)

    payload Object required

    消息内容的容器

    Properties
    Name Type Description
    text String required

    消息文本内容

    cloudCustomData String ''

    消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)

    receiverList Array | undefined

    定向接收消息的群成员列表(社群和直播群不支持)

    priority String TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL

    消息优先级

    isSupportExtension Boolean false

    是否支持消息扩展,true 支持 false 不支持(需要您购买旗舰版套餐)

    customModerationConfigurationID String | undefined

    消息自定义审核配置 ID(v3.3.0起支持) 在开通【云端审核】功能后,您可以请前往 控制台 (云端审核 -> 审核配置 -> 自定义配置 -> 添加自定义配置) 获取配置 ID。
    【自定义审核】配置流程请参考 云端审核功能
    该字段需要发消息前设置,仅用于控制发消息时的消息审核策略,其值不会存储在漫游和本地。

    Returns:

    消息实例

    Type
    Message

    createTextAtMessage(options) → {Message}

    创建可以附带 @ 提醒功能的文本消息的接口,此接口返回一个消息实例,可以在需要发送文本消息时调用 发送消息 接口发送消息。

    注意1:此接口仅用于群聊,且社群和话题不支持 @ALL。
    注意2:创建群 @ 消息不支持指定消息接收者。

    Example
    // 发送文本消息,Web 端与小程序端相同
    // 1. 创建消息实例,接口返回的实例可以上屏
    let message = chat.createTextAtMessage({
      to: 'group1',
      conversationType: TencentCloudChat.TYPES.CONV_GROUP,
      // 消息优先级,用于群聊。如果某个群的消息超过了频率限制,后台会优先下发高优先级的消息,详细请参考:https://cloud.tencent.com/document/product/269/3663#.E6.B6.88.E6.81.AF.E4.BC.98.E5.85.88.E7.BA.A7.E4.B8.8E.E9.A2.91.E7.8E.87.E6.8E.A7.E5.88.B6)
      // 支持的枚举值:TencentCloudChat.TYPES.MSG_PRIORITY_HIGH, TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL(默认), TencentCloudChat.TYPES.MSG_PRIORITY_LOW, TencentCloudChat.TYPES.MSG_PRIORITY_LOWEST
      // priority: TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL,
      payload: {
        text: '@denny @lucy @所有人 今晚聚餐,收到的请回复1',
        atUserList: ['denny', 'lucy', TencentCloudChat.TYPES.MSG_AT_ALL] // 'denny' 'lucy' 都是 userID,而非昵称
      },
      // 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
      // cloudCustomData: 'your cloud custom data'
    });
    // 2. 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    to String required

    消息接收方的 groupID

    conversationType String required

    会话类型,必须为 TencentCloudChat.TYPES.CONV_GROUP

    payload Object required

    消息内容的容器

    Properties
    Name Type Description
    text String required

    消息文本内容

    atUserList Array required

    需要 @ 的用户列表,如果需要 @ALL,请传入 TencentCloudChat.TYPES.MSG_AT_ALL 。 举个例子,假设该条文本消息希望 @ 提醒 denny 和 lucy 两个用户,同时又希望 @ 所有人,atUserList 传 ['denny', 'lucy', TencentCloudChat.TYPES.MSG_AT_ALL]

    cloudCustomData String ''

    消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)

    priority String TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL

    消息优先级

    Returns:

    消息实例

    Type
    Message

    createImageMessage(options) → {Message}

    创建图片消息的接口,此接口返回一个消息实例,可以在需要发送图片消息时调用 发送消息 接口发送消息。

    注意1:在开通【云端审核】功能后,如果您发送的图片消息内容不合规,云端审核超时后 SDK 会触发 MESSAGE_MODIFIED 事件,回调的 message 对象 hasRiskContent 值为 true。
    注意2:v3.3.0起,支持自定义消息审核策略,请参考 customModerationConfigurationID 参数的描述。

    Examples
    // Web 端发送图片消息示例1 - 传入 DOM 节点
    // 1. 创建消息实例,接口返回的实例可以上屏
    let message = chat.createImageMessage({
      to: 'user1',
      conversationType: TencentCloudChat.TYPES.CONV_C2C,
      // 消息优先级,用于群聊。如果某个群的消息超过了频率限制,后台会优先下发高优先级的消息,详细请参考:https://cloud.tencent.com/document/product/269/3663#.E6.B6.88.E6.81.AF.E4.BC.98.E5.85.88.E7.BA.A7.E4.B8.8E.E9.A2.91.E7.8E.87.E6.8E.A7.E5.88.B6)
      // 支持的枚举值:TencentCloudChat.TYPES.MSG_PRIORITY_HIGH, TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL(默认), TencentCloudChat.TYPES.MSG_PRIORITY_LOW, TencentCloudChat.TYPES.MSG_PRIORITY_LOWEST
      // priority: TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL,
      payload: {
        file: document.getElementById('imagePicker'),
      },
      // 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
      // cloudCustomData: 'your cloud custom data'
      onProgress: function(event) { console.log('file uploading:', event) }
    });
    
    // 2. 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    // Web 端发送图片消息示例2- 传入 File 对象
    // 先在页面上添加一个 id 为 "testPasteInput" 的消息输入框,如 <input type="text" id="testPasteInput" placeholder="截图后粘贴到输入框中" size="30" />
    document.getElementById('testPasteInput').addEventListener('paste', function(e) {
      let clipboardData = e.clipboardData;
      let file;
      let fileCopy;
      if (clipboardData && clipboardData.files && clipboardData.files.length > 0) {
        file = clipboardData.files[0];
        // 图片消息发送成功后,file 指向的内容可能被浏览器清空,如果接入侧有额外的渲染需求,可以提前复制一份数据
        fileCopy = file.slice();
      }
    
      if (typeof file === 'undefined') {
        console.warn('file 是 undefined,请检查代码或浏览器兼容性!');
        return;
      }
    
      // 1. 创建消息实例,接口返回的实例可以上屏
      let message = chat.createImageMessage({
        to: 'user1',
        conversationType: TencentCloudChat.TYPES.CONV_C2C,
        payload: {
          file: file
        },
        onProgress: function(event) { console.log('file uploading:', event) }
      });
    
      // 2. 发送消息
      let promise = chat.sendMessage(message);
      promise.then(function(imResponse) {
        // 发送成功
        console.log(imResponse);
      }).catch(function(imError) {
        // 发送失败
        console.warn('sendMessage error:', imError);
      });
    });
    // 小程序端发送图片(微信小程序从基础库 2.21.0 开始,wx.chooseImage 接口停止维护,请使用 wx.chooseMedia 代替)
    // 1. 选择图片
    wx.chooseMedia({
      mediaType: ['image'], // 图片
      sourceType: ['album'], // 从相册选择
      count: 1, // 只选一张,目前 SDK 不支持一次发送多张图片
      success: function (res) {
        // 2. 创建消息实例,接口返回的实例可以上屏
        let message = chat.createImageMessage({
          to: 'user1',
          conversationType: TencentCloudChat.TYPES.CONV_C2C,
          payload: { file: res },
          onProgress: function(event) { console.log('file uploading:', event) }
        });
        // 3. 发送图片
        let promise = chat.sendMessage(message);
        promise.then(function(imResponse) {
          // 发送成功
          console.log(imResponse);
        }).catch(function(imError) {
          // 发送失败
          console.warn('sendMessage error:', imError);
        });
      }
    })
    // uni-app 发送图片
    // 微信小程序从基础库 2.21.0 开始, wx.chooseImage 停止维护,请使用 uni.chooseMedia 代替
    // 1. 选择图片
    uni.chooseMedia({
      count: 1,
      mediaType: ['image'], // 图片
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
      sourceType: ['album'], // 从相册选择
      success: function(res) {
        let message = chat.createImageMessage({
          to: 'user1',
          conversationType: TencentCloudChat.TYPES.CONV_C2C,
          payload: { file: res },
          onProgress: function(event) { console.log('file uploading:', event) }
        });
        // 2. 发送消息
        let promise = chat.sendMessage(message);
        promise.then(function(imResponse) {
          // 发送成功
          console.log(imResponse);
        }).catch(function(imError) {
          // 发送失败
          console.warn('sendMessage error:', imError);
        });
      }
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    to String required

    消息接收方的 userID 或 groupID

    conversationType String required

    会话类型,取值TencentCloudChat.TYPES.CONV_C2C(端到端会话) 或 TencentCloudChat.TYPES.CONV_GROUP(群组会话)

    payload Object required

    消息内容

    Properties
    Name Type Description
    file HTMLInputElement | File | Object required

    用于选择图片的 DOM 节点(Web)或者 File 对象(Web)或者微信小程序 wx.chooseMedia 接口的 success 回调参数,或 uni.chooseMedia 接口的 success 回调参数。SDK 会读取其中的数据并上传图片。

    onProgress function required

    获取上传进度的回调函数

    cloudCustomData String ''

    消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)

    priority String TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL

    消息优先级

    customModerationConfigurationID String | undefined

    消息自定义审核配置 ID(v3.3.0起支持) 在开通【云端审核】功能后,您可以请前往 控制台 (云端审核 -> 审核配置 -> 自定义配置 -> 添加自定义配置) 获取配置 ID。
    【自定义审核】配置流程请参考 云端审核功能
    该字段需要发消息前设置,仅用于控制发消息时的消息审核策略,其值不会存储在漫游和本地。

    Returns:

    消息实例

    Type
    Message

    createAudioMessage(options) → {Message}

    创建音频消息实例的接口,此接口返回一个消息实例,可以在需要发送音频消息时调用 发送消息 接口发送消息。

    注意1:在开通【云端审核】功能后,如果您发送的音频消息内容不合规,云端异步审核后 SDK 会触发 MESSAGE_MODIFIED 事件,回调的 message 对象 hasRiskContent 值为 true。
    注意2:v3.3.0起,支持自定义消息审核策略,请参考 customModerationConfigurationID 参数的描述。

    Examples
    // 示例:使用微信官方的 RecorderManager 进行录音,参考 https://developers.weixin.qq.com/minigame/dev/api/media/recorder/RecorderManager.start.html
    // 1. 获取全局唯一的录音管理器 RecorderManager
    const recorderManager = wx.getRecorderManager();
    
    // 录音部分参数
    const recordOptions = {
      duration: 60000, // 录音的时长,单位 ms,最大值 600000(10 分钟)
      sampleRate: 44100, // 采样率
      numberOfChannels: 1, // 录音通道数
      encodeBitRate: 192000, // 编码码率
      format: 'aac' // 音频格式,选择此格式创建的音频消息,可以在即时通信 IM 全平台(Android、iOS、微信小程序和Web)互通
    };
    
    // 2.1 监听录音错误事件
    recorderManager.onError(function(errMsg) {
      console.warn('recorder error:', errMsg);
    });
    // 2.2 监听录音结束事件,录音结束后,调用 createAudioMessage 创建音频消息实例
    recorderManager.onStop(function(res) {
      console.log('recorder stop', res);
    
      // 4. 创建消息实例,接口返回的实例可以上屏
      const message = chat.createAudioMessage({
        to: 'user1',
        conversationType: TencentCloudChat.TYPES.CONV_C2C,
        // 消息优先级,用于群聊。如果某个群的消息超过了频率限制,后台会优先下发高优先级的消息,详细请参考:https://cloud.tencent.com/document/product/269/3663#.E6.B6.88.E6.81.AF.E4.BC.98.E5.85.88.E7.BA.A7.E4.B8.8E.E9.A2.91.E7.8E.87.E6.8E.A7.E5.88.B6)
        // 支持的枚举值:TencentCloudChat.TYPES.MSG_PRIORITY_HIGH, TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL(默认), TencentCloudChat.TYPES.MSG_PRIORITY_LOW, TencentCloudChat.TYPES.MSG_PRIORITY_LOWEST
        // priority: TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL,
        payload: {
          file: res
        },
        // 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
        // cloudCustomData: 'your cloud custom data'
      });
    
      // 5. 发送消息
      let promise = chat.sendMessage(message);
      promise.then(function(imResponse) {
        // 发送成功
        console.log(imResponse);
      }).catch(function(imError) {
        // 发送失败
        console.warn('sendMessage error:', imError);
      });
    });
    
    // 3. 开始录音
    recorderManager.start(recordOptions);
    // 在 Web 端创建语音消息并发送
    // 示例:使用第三方库 js-audio-recorder 录制音频
    // 1. 开始录制
    let recorder = new Recorder({
      sampleBits: 16,                 // 采样位数,支持 8 或 16,默认是16
      sampleRate: 16000,              // 采样率,支持 11025、16000、22050、24000、44100、48000,根据浏览器默认值,我的chrome是48000
      numChannels: 1,                 // 声道,支持 1 或 2, 默认是1
    });
    let startTs;
    recorder.start().then(() => {
      // 开始录音,记录起始时间戳
      startTs = Date.now();
    }, (error) => {
      // 出错了
      console.log(`${error.name} : ${error.message}`);
    });
    
    // 2. 结束录制
    recorder.stop();
    
    // 3. 计算录音时长,获取 WAV 数据
    let duration = Date.now() - startTs; // 单位:ms
    let wavBlob = recorder.getWAVBlob();
    
    // 4. blob 数据转成 File 对象
    let audioFile = new File([wavBlob], 'hello.wav', { type: 'wav' });
    audioFile.duration = duration;
    
    // 5. 创建音频消息
    let message = chat.createAudioMessage({
      to: 'user1',
      conversationType: 'C2C',
      payload: {
        file: audioFile
      }
    });
    
    // 6. 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    to String required

    消息接收方的 userID 或 groupID

    conversationType String required

    会话类型,取值TencentCloudChat.TYPES.CONV_C2C(端到端会话) 或 TencentCloudChat.TYPES.CONV_GROUP(群组会话)

    payload Object required

    消息内容

    Properties
    Name Type Description
    file Object required

    录音后得到的文件信息

    cloudCustomData String ''

    消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)

    priority String TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL

    消息优先级

    customModerationConfigurationID String | undefined

    消息自定义审核配置 ID(v3.3.0起支持) 在开通【云端审核】功能后,您可以请前往 控制台 (云端审核 -> 审核配置 -> 自定义配置 -> 添加自定义配置) 获取配置 ID。
    【自定义审核】配置流程请参考 云端审核功能
    该字段需要发消息前设置,仅用于控制发消息时的消息审核策略,其值不会存储在漫游和本地。

    Returns:

    消息实例

    Type
    Message

    createVideoMessage(options) → {Message}

    创建视频消息实例的接口,此接口返回一个消息实例,可以在需要发送视频消息时调用 发送消息 接口发送消息。

    注意1:在开通【云端审核】功能后,如果您发送的视频消息内容不合规,云端异步审核后 SDK 会触发 MESSAGE_MODIFIED 事件,回调的 message 对象 hasRiskContent 值为 true。
    注意2:v3.3.0起,支持自定义消息审核策略,请参考 customModerationConfigurationID 参数的描述。

    Examples
    // 小程序端发送视频消息示例(微信小程序从基础库 2.21.0 开始, wx.chooseVideo 停止维护,请使用 wx.chooseMedia 代替):
    // 1. 调用小程序接口选择视频,接口详情请查阅 https://developers.weixin.qq.com/miniprogram/dev/api/media/video/wx.chooseMedia.html
    wx.chooseMedia({
      mediaType: ['video'], // 视频
      sourceType: ['album', 'camera'], // 来源相册或者拍摄
      maxDuration: 60, // 设置最长时间60s
      camera: 'back', // 后置摄像头
      success (res) {
        // 2. 创建消息实例,接口返回的实例可以上屏
        let message = chat.createVideoMessage({
          to: 'user1',
          conversationType: TencentCloudChat.TYPES.CONV_C2C,
          // 消息优先级,用于群聊。如果某个群的消息超过了频率限制,后台会优先下发高优先级的消息,详细请参考:https://cloud.tencent.com/document/product/269/3663#.E6.B6.88.E6.81.AF.E4.BC.98.E5.85.88.E7.BA.A7.E4.B8.8E.E9.A2.91.E7.8E.87.E6.8E.A7.E5.88.B6)
          // 支持的枚举值:TencentCloudChat.TYPES.MSG_PRIORITY_HIGH, TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL(默认), TencentCloudChat.TYPES.MSG_PRIORITY_LOW, TencentCloudChat.TYPES.MSG_PRIORITY_LOWEST
          // priority: TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL,
          payload: {
            file: res
          },
          // 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
          // cloudCustomData: 'your cloud custom data'
          // 支持小程序端视频上传进度回调
          onProgress: function(event) { console.log('file uploading:', event) }
        })
        // 3. 发送消息
        let promise = chat.sendMessage(message);
        promise.then(function(imResponse) {
          // 发送成功
          console.log(imResponse);
        }).catch(function(imError) {
          // 发送失败
          console.warn('sendMessage error:', imError);
        });
      }
    })
    // web 端发送视频消息示例:
    // 1. 获取视频:传入 DOM 节点
    // 2. 创建消息实例
    const message = chat.createVideoMessage({
      to: 'user1',
      conversationType: TencentCloudChat.TYPES.CONV_C2C,
      payload: {
        file: document.getElementById('videoPicker') // 或者用event.target
      },
      onProgress: function(event) { console.log('file uploading:', event) }
    });
    // 3. 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    // uni-app 发送视频
    // 微信小程序从基础库 2.21.0 开始, wx.chooseVideo 停止维护,请使用 uni.chooseMedia 代替
    // 1. 选择视频
    uni.chooseMedia({
      mediaType: ['video'], // 视频
      count: 1,
      sourceType: ['camera', 'album'], // album 从相册选视频,camera 使用相机拍摄,默认为:['album', 'camera']
      maxDuration: 60, // 设置最长时间60s
      camera: 'back', // 后置摄像头
      success: function(res) {
        let message = chat.createVideoMessage({
          to: 'user1',
          conversationType: TencentCloudChat.TYPES.CONV_C2C,
          payload: { file: res },
          onProgress: function(event) { console.log('file uploading:', event) }
        });
        // 2. 发送消息
        let promise = chat.sendMessage(message);
        promise.then(function(imResponse) {
          // 发送成功
          console.log(imResponse);
        }).catch(function(imError) {
          // 发送失败
          console.warn('sendMessage error:', imError);
        });
      }
    })
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    to String required

    消息接收方的 userID 或 groupID

    conversationType String required

    会话类型,取值TencentCloudChat.TYPES.CONV_C2C(端到端会话) 或 TencentCloudChat.TYPES.CONV_GROUP(群组会话)

    payload Object required

    消息内容

    Properties
    Name Type Description
    file HTMLInputElement | File | Object required

    用于选择视频文件的 DOM 节点(Web)或者 File 对象(Web),或微信小程序录制或者从相册选择的视频文件,或 uni.chooseMedia 接口的 success 回调参数。SDK 会读取其中的数据并上传

    onProgress function required

    获取上传进度的回调函数

    cloudCustomData String ''

    消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)

    priority String TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL

    消息优先级

    customModerationConfigurationID String | undefined

    消息自定义审核配置 ID(v3.3.0起支持) 在开通【云端审核】功能后,您可以请前往 控制台 (云端审核 -> 审核配置 -> 自定义配置 -> 添加自定义配置) 获取配置 ID。
    【自定义审核】配置流程请参考 云端审核功能
    该字段需要发消息前设置,仅用于控制发消息时的消息审核策略,其值不会存储在漫游和本地。

    Returns:

    消息实例

    Type
    Message

    createCustomMessage(options) → {Message}

    创建自定义消息实例的接口,此接口返回一个消息实例,可以在需要发送自定义消息时调用 发送消息 接口发送消息。 当 SDK 提供的能力不能满足您的需求时,可以使用自定义消息进行个性化定制,例如投骰子功能。

    注意1:v3.3.0起,支持自定义消息审核策略,请参考 customModerationConfigurationID 参数的描述。

    Example
    // 示例:利用自定义消息实现投骰子功能
    // 1. 定义随机函数
    function random(min, max) {
      return Math.floor(Math.random() * (max - min + 1) + min);
    }
    // 2. 创建消息实例,接口返回的实例可以上屏
    let message = chat.createCustomMessage({
      to: 'user1',
      conversationType: TencentCloudChat.TYPES.CONV_C2C,
      // 消息优先级,用于群聊。如果某个群的消息超过了频率限制,后台会优先下发高优先级的消息,详细请参考:https://cloud.tencent.com/document/product/269/3663#.E6.B6.88.E6.81.AF.E4.BC.98.E5.85.88.E7.BA.A7.E4.B8.8E.E9.A2.91.E7.8E.87.E6.8E.A7.E5.88.B6)
      // 支持的枚举值:TencentCloudChat.TYPES.MSG_PRIORITY_HIGH, TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL(默认), TencentCloudChat.TYPES.MSG_PRIORITY_LOW, TencentCloudChat.TYPES.MSG_PRIORITY_LOWEST
      // priority: TencentCloudChat.TYPES.MSG_PRIORITY_HIGH,
      payload: {
        data: 'dice', // 用于标识该消息是骰子类型消息
        description: String(random(1,6)), // 获取骰子点数
        extension: ''
      }
    });
    // 3. 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    to String required

    消息接收方的 userID 或 groupID

    conversationType String required

    会话类型,取值TencentCloudChat.TYPES.CONV_C2C(端到端会话) 或 TencentCloudChat.TYPES.CONV_GROUP(群组会话)

    payload Object required

    消息内容

    Properties
    Name Type Description
    data String required

    自定义消息的数据字段

    description String required

    自定义消息的说明字段

    extension String required

    自定义消息的扩展字段

    cloudCustomData String ''

    消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)

    priority String TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL

    消息优先级

    customModerationConfigurationID String | undefined

    消息自定义审核配置 ID(v3.3.0起支持) 在开通【云端审核】功能后,您可以请前往 控制台 (云端审核 -> 审核配置 -> 自定义配置 -> 添加自定义配置) 获取配置 ID。
    【自定义审核】配置流程请参考 云端审核功能
    该字段需要发消息前设置,仅用于控制发消息时的消息审核策略,其值不会存储在漫游和本地。

    Returns:

    消息实例

    Type
    Message

    createFaceMessage(options) → {Message}

    创建表情消息实例的接口,此接口返回一个消息实例,可以在需要发送表情消息时调用 发送消息 接口发送消息。

    Example
    // 发送表情消息,Web端与小程序端相同。
    // 1. 创建消息实例,接口返回的实例可以上屏
    let message = chat.createFaceMessage({
      to: 'user1',
      conversationType: TencentCloudChat.TYPES.CONV_C2C,
      // 消息优先级,用于群聊。如果某个群的消息超过了频率限制,后台会优先下发高优先级的消息,详细请参考:https://cloud.tencent.com/document/product/269/3663#.E6.B6.88.E6.81.AF.E4.BC.98.E5.85.88.E7.BA.A7.E4.B8.8E.E9.A2.91.E7.8E.87.E6.8E.A7.E5.88.B6)
      // 支持的枚举值:TencentCloudChat.TYPES.MSG_PRIORITY_HIGH, TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL(默认), TencentCloudChat.TYPES.MSG_PRIORITY_LOW, TencentCloudChat.TYPES.MSG_PRIORITY_LOWEST
      // priority: TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL,
      payload: {
        index: 1, // Number 表情索引,用户自定义
        data: 'tt00' // String 额外数据
      },
      // 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
      // cloudCustomData: 'your cloud custom data'
    });
    // 2. 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    to String required

    消息接收方的 userID 或 groupID

    conversationType String required

    会话类型,取值TencentCloudChat.TYPES.CONV_C2C(端到端会话) 或 TencentCloudChat.TYPES.CONV_GROUP(群组会话)

    payload Object required

    消息内容

    Properties
    Name Type Description
    index Number required

    表情索引,用户自定义

    data String required

    额外数据

    cloudCustomData String ''

    消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)

    priority String TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL

    消息优先级

    Returns:

    消息实例

    Type
    Message

    createFileMessage(options) → {Message}

    创建文件消息的接口,此接口返回一个消息实例,可以在需要发送文件消息时调用 发送消息 接口发送消息。

    Examples
    // Web 端发送文件消息示例1 - 传入 DOM 节点
    // 1. 创建文件消息实例,接口返回的实例可以上屏
    let message = chat.createFileMessage({
      to: 'user1',
      conversationType: TencentCloudChat.TYPES.CONV_C2C,
      // 消息优先级,用于群聊。如果某个群的消息超过了频率限制,后台会优先下发高优先级的消息,详细请参考:https://cloud.tencent.com/document/product/269/3663#.E6.B6.88.E6.81.AF.E4.BC.98.E5.85.88.E7.BA.A7.E4.B8.8E.E9.A2.91.E7.8E.87.E6.8E.A7.E5.88.B6)
      // 支持的枚举值:TencentCloudChat.TYPES.MSG_PRIORITY_HIGH, TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL(默认), TencentCloudChat.TYPES.MSG_PRIORITY_LOW, TencentCloudChat.TYPES.MSG_PRIORITY_LOWEST
      // priority: TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL,
      payload: {
        file: document.getElementById('filePicker'),
      },
      // 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
      // cloudCustomData: 'your cloud custom data'
      onProgress: function(event) { console.log('file uploading:', event) }
    });
    
    // 2. 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    // Web 端发送文件消息示例2- 传入 File 对象
    // 先在页面上添加一个 id 为 "testPasteInput" 的消息输入框,如 <input type="text" id="testPasteInput" placeholder="截图后粘贴到输入框中" size="30" />
    document.getElementById('testPasteInput').addEventListener('paste', function(e) {
      let clipboardData = e.clipboardData;
      let file;
      let fileCopy;
      if (clipboardData && clipboardData.files && clipboardData.files.length > 0) {
        file = clipboardData.files[0];
        // 图片消息发送成功后,file 指向的内容可能被浏览器清空,如果接入侧有额外的渲染需求,可以提前复制一份数据
        fileCopy = file.slice();
      }
    
      if (typeof file === 'undefined') {
        console.warn('file 是 undefined,请检查代码或浏览器兼容性!');
        return;
      }
    
      // 1. 创建消息实例,接口返回的实例可以上屏
      let message = chat.createFileMessage({
        to: 'user1',
        conversationType: TencentCloudChat.TYPES.CONV_C2C,
        payload: {
          file: file
        },
        onProgress: function(event) { console.log('file uploading:', event) }
      });
    
      // 2. 发送消息
      let promise = chat.sendMessage(message);
      promise.then(function(imResponse) {
        // 发送成功
        console.log(imResponse);
      }).catch(function(imError) {
        // 发送失败
        console.warn('sendMessage error:', imError);
      });
    });
    // uni-app 发送文件
    // 1. 选择文件
    uni.chooseFile({
      count: 1,
      extension:['.zip','.doc'],
      success: function(res) {
        let message = chat.createFileMessage({
          to: 'user1',
          conversationType: TencentCloudChat.TYPES.CONV_C2C,
          payload: { file: res },
          onProgress: function(event) { console.log('file uploading:', event) }
        });
        // 2. 发送消息
        let promise = chat.sendMessage(message);
        promise.then(function(imResponse) {
          // 发送成功
          console.log(imResponse);
        }).catch(function(imError) {
          // 发送失败
          console.warn('sendMessage error:', imError);
        });
      }
    });
    // 手机端微信小程序或 QQ 小程序法发送文件
    // wx.chooseMessageFile 基础库 2.5.0 开始支持,低版本需做兼容处理
    // qq.chooseMessageFile 基础库 1.18.0 开始支持,低版本需做兼容处理
    // 1. 从客户端会话选择文件
    wx.chooseMessageFile({
      count: 1,
      type: 'all', // 从所有文件选择
      success: (res) => {
        const message = chat.createFileMessage({
          to: 'user1',
          conversationType: TencentCloudChat.TYPES.CONV_C2C,
          payload: { file: res },
          onProgress: function(event) { console.log('file uploading:', event) }
        });
        // 2. 发送消息
        let promise = chat.sendMessage(message);
        promise.then(function(imResponse) {
          // 发送成功
          console.log(imResponse);
        }).catch(function(imError) {
          // 发送失败
          console.warn('sendMessage error:', imError);
        });
      }
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    to String required

    消息接收方的 userID 或 groupID

    conversationType String required

    会话类型,取值TencentCloudChat.TYPES.CONV_C2C(端到端会话) 或 TencentCloudChat.TYPES.CONV_GROUP(群组会话)

    payload Object required

    消息内容

    Properties
    Name Type Description
    file HTMLInputElement | File | Object required

    用于选择文件的 DOM 节点(Web)或者 File 对象(Web)或者 Object(uni.chooseFile 接口的 success 回调参数),SDK 会读取其中的数据并上传文件。

    onProgress function required

    获取上传进度的回调函数

    cloudCustomData String ''

    消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)

    priority String TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL

    消息优先级

    Returns:

    消息实例

    Type
    Message

    createLocationMessage(options) → {Message}

    创建地理位置消息的接口,此接口返回一个消息实例,可以在需要发送地理位置消息时调用 发送消息 接口发送消息。

    Example
    // 发送地理位置消息,Web 端与小程序端相同
    // 1. 创建消息实例,接口返回的实例可以上屏
    let message = chat.createLocationMessage({
      to: 'user1',
      conversationType: TencentCloudChat.TYPES.CONV_C2C,
      // 消息优先级,用于群聊。如果某个群的消息超过了频率限制,后台会优先下发高优先级的消息,详细请参考:https://cloud.tencent.com/document/product/269/3663#.E6.B6.88.E6.81.AF.E4.BC.98.E5.85.88.E7.BA.A7.E4.B8.8E.E9.A2.91.E7.8E.87.E6.8E.A7.E5.88.B6)
      // 支持的枚举值:TencentCloudChat.TYPES.MSG_PRIORITY_HIGH, TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL(默认), TencentCloudChat.TYPES.MSG_PRIORITY_LOW, TencentCloudChat.TYPES.MSG_PRIORITY_LOWEST
      // priority: TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL,
      payload: {
        description: '深圳市深南大道10000号腾讯大厦',
        longitude: 113.941079, // 经度
        latitude: 22.546103 // 纬度
      }
    });
    // 2. 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    to String required

    消息接收方的 userID 或 groupID

    conversationType String required

    会话类型,取值TencentCloudChat.TYPES.CONV_C2C(端到端会话) 或 TencentCloudChat.TYPES.CONV_GROUP(群组会话)

    payload Object required

    消息内容

    Properties
    Name Type Description
    description String required

    地理位置描述信息

    longitude Number required

    经度

    latitude Number required

    纬度

    cloudCustomData String ''

    消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)

    priority String TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL

    消息优先级

    Returns:

    消息实例

    Type
    Message

    createMergerMessage(options) → {Message}

    创建合并消息的接口,此接口返回一个消息实例,可以在需要发送合并消息时调用 发送消息 接口发送消息。

    注意1:不支持合并已发送失败的消息,如果消息列表内传入了已发送失败的消息,则创建消息接口会报错。

    Example
    // 1. 将群聊消息转发到 c2c 会话
    // message1 message2 message3 是群聊消息
    let mergerMessage = chat.createMergerMessage({
      to: 'user1',
      conversationType: TencentCloudChat.TYPES.CONV_C2C,
      payload: {
        messageList: [message1, message2, message3],
        title: '大湾区前端人才中心的聊天记录',
        abstractList: ['allen: 666', 'iris: [图片]', 'linda: [文件]'],
        compatibleText: '请升级IMSDK到v2.10.1或更高版本查看此消息'
      },
      // 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
      // cloudCustomData: 'your cloud custom data'
    });
    
    // 2. 发送消息
    let promise = chat.sendMessage(mergerMessage);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    to String required

    消息接收方的 userID 或 groupID

    conversationType String required

    会话类型,取值TencentCloudChat.TYPES.CONV_C2C(端到端会话) 或 TencentCloudChat.TYPES.CONV_GROUP(群组会话)

    payload Object required

    消息内容

    Properties
    Name Type Description
    messageList Array.<Message> required

    合并的消息列表

    title String required

    合并的标题,比如:"大湾区前端人才中心的聊天记录"

    abstractList String required

    摘要列表,不同的消息类型可以设置不同的摘要信息,比如:文本消息可以设置为:sender: text,图片消息可以设置为:sender: [图片],文件消息可以设置为:sender: [文件]

    compatibleText String required

    兼容文本,低版本 SDK 如果不支持合并消息,默认会收到一条文本消息,文本消息的内容为 ${compatibleText},必填。

    cloudCustomData String ''

    消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)

    priority String TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL

    消息优先级

    Returns:

    消息实例

    Type
    Message

    downloadMergerMessage(message) → {Promise}

    下载合并消息的接口。如果发送方发送的合并消息较大,SDK 会将此消息存储到云端,消息接收方查看消息时,需要先把消息从云端下载到本地。

    Example
    // downloadKey 存在说明收到的合并消息存储在云端,需要先下载
    if (message.type === TencentCloudChat.TYPES.MSG_MERGER && message.payload.downloadKey !== '') {
      let promise = chat.downloadMergerMessage(message);
      promise.then(function(imResponse) {
        // 下载成功后,SDK会更新 message.payload.messageList 等信息
        console.log(imResponse.data);
      }).catch(function(imError) {
        // 下载失败
        console.warn('downloadMergerMessage error:', imError);
      });
    }
    Parameters:
    Name Type Description
    message Message required

    消息实例

    Returns:
    Type
    Promise

    createForwardMessage(options) → {Message}

    创建转发消息的接口,此接口返回一个消息实例,可以在需要发送转发消息时调用 发送消息 接口发送消息。

    注意1:支持单条转发和逐条转发。

    Example
    let forwardMessage = chat.createForwardMessage({
      to: 'user1',
      conversationType: TencentCloudChat.TYPES.CONV_C2C,
      // 消息优先级,用于群聊,如果某个群的消息超过了频率限制,后台会优先下发高优先级的消息,详细请参考:https://cloud.tencent.com/document/product/269/3663#.E6.B6.88.E6.81.AF.E4.BC.98.E5.85.88.E7.BA.A7.E4.B8.8E.E9.A2.91.E7.8E.87.E6.8E.A7.E5.88.B6)
      // 支持的枚举值:TencentCloudChat.TYPES.MSG_PRIORITY_HIGH, TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL(默认), TencentCloudChat.TYPES.MSG_PRIORITY_LOW, TencentCloudChat.TYPES.MSG_PRIORITY_LOWEST
      // priority: TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL,
      payload: message, // 消息实例,已收到的或自己已发出的消息
      // 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
      // cloudCustomData: 'your cloud custom data'
    });
    // 2. 发送消息
    let promise = chat.sendMessage(forwardMessage);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    to String required

    消息接收方的 userID 或 groupID

    conversationType String required

    会话类型,取值TencentCloudChat.TYPES.CONV_C2C(端到端会话) 或 TencentCloudChat.TYPES.CONV_GROUP(群组会话)

    payload Message required

    消息实例

    cloudCustomData String ''

    消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)

    priority String TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL

    消息优先级

    Returns:

    消息实例

    Type
    Message

    sendMessage(message, optionsopt) → {Promise}

    发送消息的接口,需先调用下列的创建消息实例的接口获取消息实例后,再调用该接口发送消息实例。

    注意1:调用该接口发送消息实例,需要 SDK 处于 ready 状态,否则将无法发送消息实例。sdk 状态,可通过监听以下事件得到:

    注意2:接收推送的单聊、群聊、群提示、群系统通知的新消息,需监听事件 TencentCloudChat.EVENT.MESSAGE_RECEIVED
    注意3:本实例发送的消息,不会触发事件 TencentCloudChat.EVENT.MESSAGE_RECEIVED。同账号从其他端(或通过 REST API)发送的消息,会触发事件 TencentCloudChat.EVENT.MESSAGE_RECEIVED
    注意4:离线推送仅适用于终端(Android 或 iOS),Web 和 微信小程序不支持。
    注意5:onlineUserOnly 和 messageControlInfo 不能同时使用。
    注意6:支持普通社群和话题消息不计未读。
    注意7:向【系统会话】发消息,SDK 返回错误码 2106。
    注意8:消息包体大小限制为12KB,且不可调整,超出会导致消息发送失败,错误码 80002。
    注意9:启用好友关系检查后(【IM 控制台】>【应用配置】>【功能配置】>【登录与消息】>【好友关系检查】),IM 会在发起单聊时检查好友关系,仅允许好友之间发送单聊消息,陌生人发送单聊消息时 SDK 返回错误码 20009。

    Examples
    // 如果接收方不在线,则消息将存入漫游,且进行离线推送(在接收方 App 退后台或者进程被 kill 的情况下)。离线推送的标题和内容使用默认值。
    // 离线推送的说明请参考 https://cloud.tencent.com/document/product/269/103522
    chat.sendMessage(message);
    // 消息发送选项
    chat.sendMessage(message, {
      onlineUserOnly: true // 如果接收方不在线,则消息不存入漫游,且不会进行离线推送
    });
    // 消息发送选项
    chat.sendMessage(message, {
      offlinePushInfo: {
        disablePush: true // 如果接收方不在线,则消息将存入漫游,但不进行离线推送
      }
    });
    // 消息发送选项
    chat.sendMessage(message, {
      // 如果接收方不在线,则消息将存入漫游,且进行离线推送(在接收方 App 退后台或者进程被 kill 的情况下)。接入侧可自定义离线推送的标题及内容
      offlinePushInfo: {
        title: '', // 离线推送标题
        description: '', // 离线推送内容
        androidOPPOChannelID: '' // 离线推送设置 OPPO 手机 8.0 系统及以上的渠道 ID
      }
    });
    // 消息控制选项
    chat.sendMessage(message, {
      messageControlInfo: {
        excludedFromUnreadCount: true, // 消息不更新会话 unreadCount(消息存漫游)
        excludedFromLastMessage: true // 消息不更新会话 lastMessage(消息存漫游)
      }
    });
    // 普通社群消息不计未读
    chat.sendMessage(message, {
      messageControlInfo: {
        excludedFromUnreadCount: true, // 消息不更新会话 unreadCount(消息存漫游)
      }
    });
    // 话题消息不计未读
    chat.sendMessage(message, {
      messageControlInfo: {
        excludedFromUnreadCount: true, // 消息不更新话题 unreadCount(消息存漫游)
      }
    });
    // 支持 voip 推送
    chat.sendMessage(message, {
      offlinePushInfo: {
        disablePush: false, // 如果接收方不在线,则进行离线推送
        disableVoipPush: false // 开启 voip 推送需要同时开启离线推送
      }
    });
    // 消息不过内容审核
    // 只有在开通【云端审核】功能后,excludedFromContentModeration 设置才有效,设置为 true,消息不过内容审核,设置为 false 消息过内容审核
    //【云端审核】开通流程请参考 [云端审核功能](https://cloud.tencent.com/document/product/269/83795#.E4.BA.91.E7.AB.AF.E5.AE.A1.E6.A0.B8.E5.8A.9F.E8.83.BD)
    chat.sendMessage(message, {
      messageControlInfo: {
        excludedFromContentModeration: true,
      }
    });
    Parameters:
    Name Type Description
    message Message required

    消息实例

    options Object

    消息发送选项

    Properties
    Name Type Default Description
    onlineUserOnly Boolean false

    消息是否仅发送给在线用户的标识,默认值为 false;设置为 true,则消息既不存漫游,也不会计入未读,也不会离线推送给接收方。适合用于发送广播通知等不重要的提示消息场景。在 AVChatRoom 发送消息不支持此选项。

    offlinePushInfo Object

    离线推送配置

    • 注意:消息接收方需集成 TIMPush
    Properties
    Name Type Description
    disablePush Boolean

    true 关闭离线推送;false 开启离线推送(默认)

    disableVoipPush Boolean

    true 关闭 voip 推送(默认);false 开启 voip 推送(开启 voip 推送需要同时开启离线推送)

    title String

    离线推送标题。该字段为 iOS 和 Android 共用

    description String

    离线推送内容。该字段会覆盖消息实例的离线推送展示文本。若发送的是自定义消息,该 description 字段会覆盖 message.payload.description。如果 description 和 message.payload.description 字段都不填,接收方将收不到该自定义消息的离线推送

    extension String

    离线推送透传内容

    androidInfo Object

    Android 推送配置。v3.3.2 起支持。

    Properties
    Name Type Description
    sound String

    Android 离线推送声音设置。只支持华为、小米和谷歌。

    • 小米手机在 Android 8.0 及以上版本必须设置 androidInfo.XiaoMiChannelID,请您参考:小米自定义铃声
    • 谷歌手机 FCM 推送在 Android 8.0 及以上系统设置声音提示,必须设置 androidInfo.FCMChannelID。
    • 自定义铃音需要设置声音文件路径。例如: androidInfo.sound = "shake.xxx"
      • 对应 uniapp "nativeResources/android/res/raw/shake.xxx" 音频文件.
      • 对应原生应用的 "/res/raw/shake.xxx" 音频文件。
    XiaoMiChannelID String

    小米手机 MIUI 10 及以上的通知类别(Channel)适配字段。

    OPPOChannelID String

    OPPO 手机 Android 8.0 及以上的 NotificationChannel 通知适配字段。

    FCMChannelID String

    Google 手机 Android 8.0 及以上的通知渠道字段。

    VIVOClassification Number

    VIVO 手机推送消息分类,0:运营消息,1:系统消息,默认为1。

    VIVOCategory String

    VIVO 手机用来标识消息类型。

    HuaWeiCategory String

    华为手机用来标识消息类型。

    apnsInfo Object

    iOS 推送配置。v3.3.2 起支持。

    Properties
    Name Type Description
    sound String

    iOS 离线推送声音设置。

    • 当 apnsInfo.sound = TencentCloudChat.TYPES.IOS_OFFLINE_PUSH_NO_SOUND,表示接收时不会播放声音。
    • 当 apnsInfo.sound = TencentCloudChat.TYPES.IOS_OFFLINE_PUSH_DEFAULT_SOUND,表示接收时播放系统声音。
    • 自定义铃音需要设置声音文件路径。例如: apnsInfo.sound = "shake.xxx"
      • 对应 uniapp "nativeResources/ios/Resources/shake.xxx" 文件,uniapp 必须为正式包。
      • 对应原生 Xcode 工程中的 "shake.xxx" 音频文件。
    ignoreIOSBadge Boolean

    离线推送忽略 badge 计数(仅对 iOS 生效),默认为 false,设置为 true 时,在 iOS 接收端,这条消息不会使 APP 的应用图标未读计数增加。

    disableVoipPush Boolean

    true 关闭 voip 推送(默认);false 开启 voip 推送(开启 voip 推送需要同时开启离线推送)

    messageControlInfo Object

    消息控制信息。

    Properties
    Name Type Default Description
    excludedFromUnreadCount Boolean false

    true 消息不更新会话 unreadCount(消息存漫游)

    excludedFromLastMessage Boolean false

    true 消息不更新会话 lastMessage(消息存漫游)

    excludedFromContentModeration Boolean false

    消息是否不过内容审核(云端审核)

    • 只有在开通【云端审核】功能后,excludedFromContentModeration 设置才有效,设置为 true,消息不过内容审核,设置为 false 消息过内容审核。
    • 【云端审核】开通流程请参考 云端审核功能
    Returns:
    Type
    Promise

    searchCloudMessages(options) → {Promise}

    搜索云端消息,v3.1起支持。

    注意1:此功能属于增值服务,需要您购买云端搜索插件,请点击 购买
    注意2:此接口本地限频 2 次/秒。
    注意3:搜索【全部会话】的消息,如果匹配到的消息数量 messageCount > 1,则接口返回的 messageList 为 [],您可以在 UI 上展示 【${messageCount} 条相关记录】。如果您想高亮展示匹配到的消息,请参考【指定搜索】,将接口返回的 messageList 高亮展示。
    注意4:搜索【全部会话】的消息,如果某个会话中匹配到的消息条数 = 1,则 messageList 为匹配到的那条消息。
    注意5:社群、topic、直播群,不支持搜索云端消息。

    Examples
    // 全量搜索,指定关键字
    // - 搜索消息里出现 ‘你好’ 或 ‘在哪里’
    let promise = chat.searchCloudMessages({
       keywordList: ['你好', '在哪里'],
    });
    // 全量搜索,指定关键字和匹配类型搜索
    // - 搜索消息里出现了 ‘你好’ 与 ‘在哪里’ 的消息
    let promise = chat.searchCloudMessages({
       keywordList: ['你好', '在哪里'],
       keywordListMatchType: 'and',
    });
    // 全量搜索,指定关键字列表和消息发送者搜索
    // - 搜索消息发送者为 ‘user1’ 或 ‘user2’,且消息里出现了 ‘你好’ 或 ‘在哪里’ 的消息
    let promise = chat.searchCloudMessages({
       keywordList: ['你好', '在哪里'],
       senderUserIDList: ['user1', 'user2'],
    });
    // 全量搜索,指定关键字和消息类型搜索
    // - 搜索消息类型为 ‘文本消息’ 或 ‘自定义消息’,且消息里出现了 ‘你好’ 或 ‘在哪里’ 的消息
    let promise = chat.searchCloudMessages({
       keywordList: ['你好', '在哪里'],
       messageTypeList: [TencentCloudChat.TYPES.MSG_TEXT, TencentCloudChat.TYPES.MSG_CUSTOM],
    });
    // 全量搜索,搜索所有图片消息(当指定发送者或消息类型时,关键字列表可以为空)
    let promise = chat.searchCloudMessages({
       messageTypeList: [TencentCloudChat.TYPES.MSG_IMAGE],
    });
    // 全量搜索,只指定消息发送者和消息类型搜索(当指定发送者或消息类型时,关键字列表可以为空)
    // - 搜索消息发送者为 ‘user1’ 或 ‘user2’,且消息类型为 ‘文本消息’ 或 ‘自定义消息’ 的消息
    let promise = chat.searchCloudMessages({
       senderUserIDList: ['user1', 'user2'],
       messageTypeList: [TencentCloudChat.TYPES.MSG_TEXT, TencentCloudChat.TYPES.MSG_CUSTOM],
    });
    // 全量搜索,指定关键字和时间(过去一天)搜索
    // - 搜索过去一天,消息里出现了 ‘你好’ 或 ‘在哪里’的消息
    let promise = chat.searchCloudMessages({
       keywordList: ['你好', '在哪里'],
       timePosition: Number((new Date().getTime()/1000).toFixed(0)),
       timePeriod: 24 * 60 * 60,
    });
    promise.then(function(imResponse) {
     // 搜索消息成功
       const { totalCount, cursor, searchResultList } = imResponse.data;
       console.log(totalCount); // 满足搜索条件的消息所在的所有会话总数量
       console.log(cursor); // 下一次云端搜索的起始位置, 如果没有表示搜索结果拉取完成
       console.log(searchResultList); // 满足搜索条件的消息根据会话 ID 分组,分页返回分组结果
       for (let i = 0; i < searchResultList.length; i++) {
          const searchResultItem = searchResultList[i];
          const { conversationID, messageCount, messageList } = searchResultItem;
          console.log(conversationID); // 会话 ID
          console.log(messageCount); // 当前会话一共搜索到了多少条符合要求的消息
          // 本次搜索【全部会话】,那么 messageList 中装载的消息条数会有如下两种可能:
          // - 如果某个会话中匹配到的消息条数 > 1,则 messageList 为空,您可以在 UI 上显示“ messageCount 条相关记录”。
          // - 如果某个会话中匹配到的消息条数 = 1,则 messageList 为匹配到的那条消息,您可以在 UI 上显示之,并高亮匹配关键词。
          console.log(messageList);
        }
    }).catch(function(imError) {
       console.error(imError); // 搜索消息失败
    });
    // 指定会话,指定关键字搜索
    // - 搜索在 'GROUPPublic001' 会话中,消息里出现 ‘你好’ 或 ‘在哪里’ 的消息。
    let promise = chat.searchCloudMessages({
       keywordList: ['你好', '在哪里'],
       conversationID: 'GROUPPublic001'
    });
    // 指定会话,指定消息类型搜索(当指定发送者或消息类型时,关键字列表可以为空)
    // - 在 'GROUPPublic001' 会话中,搜索图片消息。
    let promise = chat.searchCloudMessages({
       conversationID: 'GROUPPublic001',
       messageTypeList: [TencentCloudChat.TYPES.MSG_IMAGE],
    });
    // 指定会话,指定关键字和消息类型搜索
    // - 搜索在 'GROUPPublic001' 会话中,消息里出现 ‘你好’ 或 ‘在哪里’,且消息类型为 ‘文本消息’ 或 ’自定义消息’ 的消息。
    let promise = chat.searchCloudMessages({
       keywordList: ['你好', '在哪里'],
       conversationID: 'GROUPPublic001'
       messageTypeList: [TencentCloudChat.TYPES.MSG_TEXT, TencentCloudChat.TYPES.MSG_CUSTOM],
    });
    // 指定会话,指定关键字和时间(过去一天)搜索
    // - 搜索过去一天,在 'GROUPPublic001' 会话中,消息里出现 ‘你好’ 或 ‘在哪里’ 的消息。
    let promise = chat.searchCloudMessages({
       keywordList: ['你好', '在哪里'],
       conversationID: 'GROUPPublic001'
       timePosition: Number((new Date().getTime()/1000).toFixed(0)),
       timePeriod: 24 * 60 * 60,
    });
    promise.then(function(imResponse) {
       // 搜索消息成功
       const { totalCount, cursor, searchResultList } = imResponse.data;
       console.log(totalCount); // 满足搜索条件的消息总数量
       console.log(cursor); // 下一次云端搜索的起始位置, 如果没有表示搜索结果拉取完成
       console.log(searchResultList); // 当前会话搜索的消息结果
       const { conversationID, messageCount, messageList } = searchResultList[0];
       console.log(conversationID); // 会话ID
       console.log(messageCount); // 当前会话一共搜索到了多少条符合要求的消息
       console.log(messageList); // 本会话中所有满足搜索条件的消息列表
    }).catch(function(imError); {
       console.error(imError); // 搜索消息失败
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    keywordList Array.<String> required

    关键字列表,最多支持 5 个。当消息发送者以及消息类型均未指定时,关键字列表必须非空;否则,关键字列表可以为空。

    keywordListMatchType String

    关键字列表匹配类型,or: “或”关系搜索(默认); and: “与”关系搜索

    senderUserIDList Array.<String>

    指定 userID 发送的消息,最多支持 5 个。

    messageTypeList Array.<String>

    指定搜索的消息类型集合,默认搜索全部类型。

    • 不传入时,表示搜索支持的全部类型消息(TencentCloudChat.TYPES.MSG_FACE、TencentCloudChat.TYPES.MSG_GRP_TIP 和 TencentCloudChat.TYPES.MSG_GRP_SYS_NOTICE 不支持)
    • 传值时,取值详见 TencentCloudChat.TYPES
    conversationID String

    搜索“全部会话”还是搜索“指定的会话”,不传入时,表示全部会话,默认:全部会话。会话 ID 组成方式:

    • C2C${userID}(单聊)
    • GROUP${groupID}(群聊)
    • 社群、topic、直播群,不支持搜索云端消息
    timePosition Number

    搜索的起始时间点。默认为 0 即代表从现在开始搜索。单位:秒

    timePeriod Number

    从起始时间点开始的过去时间范围,单位秒。默认为 0 即代表不限制时间范围,传 24 * 60 * 60 代表过去一天。

    cursor String

    每次云端搜索的起始位置。第一次搜索时不要传入 cursor,继续搜索时填入上次调用 searchCloudMessages 接口返回的 cursor 的值

    • 注意:全量搜索时,cursor 的有效期为 2 分钟。
    Returns:
    Type
    Promise

    revokeMessage(message) → {Promise}

    撤回单聊消息或者群聊消息。撤回成功后,消息对象的 isRevoked 属性值为 true。

    注意1:消息可撤回时间默认为2分钟。可通过 控制台 调整消息可撤回时间。
    注意2:被撤回的消息,可以调用 getMessageList 接口从单聊或者群聊消息漫游中拉取到。接入侧须根据消息对象的 isRevoked 属性妥善处理被撤回消息的展示。如单聊会话内可展示为 "对方撤回了一条消息";群聊会话内可展示为 "XXX撤回了一条消息"。
    注意3:可使用 REST API 撤回单聊消息撤回群聊消息
    注意4:v3.1.2起支持撤回直播群(AVChatRoom)的消息。

    Examples
    // 主动撤回消息
    let promise = chat.revokeMessage(message);
    promise.then(function(imResponse) {
      // 消息撤回成功
    }).catch(function(imError) {
      // 消息撤回失败
      console.warn('revokeMessage error:', imError);
    });
    // 收到消息被撤回的通知
    chat.on(TencentCloudChat.EVENT.MESSAGE_REVOKED, function(event) {
      // event.name - TencentCloudChat.EVENT.MESSAGE_REVOKED
      // event.data - 存储 Message 对象的数组 - [Message] - 每个 Message 对象的 isRevoked 属性值为 true
    });
    // 获取会话的消息列表时遇到被撤回的消息
    let promise = chat.getMessageList({conversationID: 'C2Ctest'});
    promise.then(function(imResponse) {
      const messageList = imResponse.data.messageList; // 消息列表
      messageList.forEach(function(message) {
        if (message.isRevoked) {
          // 处理被撤回的消息
        } else {
          // 处理普通消息
        }
      });
    });
    Parameters:
    Name Type Description
    message Message required

    消息实例

    Returns:
    Type
    Promise

    resendMessage(message, optionsopt) → {Promise}

    重发消息的接口,当消息发送失败时,可调用该接口进行重发。

    Examples
    // 重发消息
    let promise = chat.resendMessage(message); // 传入需要重发的消息实例
    promise.then(function(imResponse) {
      // 重发成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 重发失败
      console.warn('resendMessage error:', imError);
    });
    // 重发消息时带上消息控制选项
    chat.resendMessage(message, {
      messageControlInfo: {
        excludedFromUnreadCount: true, // 消息不更新会话 unreadCount(消息存漫游)
        excludedFromLastMessage: true // 消息不更新会话 lastMessage(消息存漫游)
      }
    });
    Parameters:
    Name Type Description
    message Message required

    待重发的消息实例

    options Object

    消息发送选项。同 sendMessage 的 options 一样。

    Returns:
    Type
    Promise

    deleteMessage(messageList) → {Promise}

    删除消息的接口。删除成功后,被删除消息的 isDeleted 属性值为 true。
    C2C 会话,消息被删除后,下次登录拉取历史消息将拉取不到,对端不受影响。
    群会话,消息被删除后,下次登录拉取历史消息将拉取不到,群内其他成员不受影响。

    注意1:一次最多只能删除30条消息,超过30条则只删除前30条
    注意2:要删除的消息必须属于同一会话,以消息列表的第1个消息的所属会话为准
    注意3:一秒钟最多只能调用一次该接口
    注意4:删除消息不支持多端同步
    注意5:AVChatRoom(直播群)不支持删除消息,调用此接口将返回10035错误码
    注意6:不支持删除群系统通知

    Example
    // 删除消息
    let promise = chat.deleteMessage([message1, message2, message3, ...]);
    promise.then(function(imResponse) {
      // 删除消息成功
    }).catch(function(imError) {
      // 删除消息失败
      console.warn('deleteMessage error:', imError);
    });
    Parameters:
    Name Type Description
    messageList Array required

    同一会话的消息列表,最大长度为30

    Returns:
    Type
    Promise

    translateText(options) → {Promise}

    翻译文本的接口。

    注意1:此功能当前处于限免阶段,您可通过即时通信 IM 功能及购买咨询交流群联系我们为您开通体验完整功能。

    Examples
    // 将阿拉伯文翻译成英文
    let promise = chat.translateText({
      sourceTextList: ['مرحبًا'],
      sourceLanguage: 'auto',
      targetLanguage: 'en'
    });
    promise.then(function(imResponse) {
      // 翻译成功 translatedTextList 和 sourceTextList 的元素一一对应
      const { translatedTextList } = imResponse.data;
    }).catch(function(imError) {
      // 翻译失败,错误码2117
      console.warn('translateText error:', imError);
    });
    // 将英文翻译成中文
    let promise = chat.translateText({
      sourceTextList: ['Hello Tencent', 'Build in-app chat with Tencent Cloud Chat'],
      sourceLanguage: 'auto',
      targetLanguage: 'zh'
    });
    promise.then(function(imResponse) {
      // 翻译成功 translatedTextList 和 sourceTextList 的元素一一对应
      const { translatedTextList } = imResponse.data;
    }).catch(function(imError) {
      // 翻译失败,错误码2117
      console.warn('translateText error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    sourceTextList Array required

    待翻译文本数组

    sourceLanguage String required

    源语言。可以设置为特定语言或 "auto"。"auto" 表示自动识别源语言。

    targetLanguage String required

    目标语言。支持的目标语言有多种,例如:英语-"en",简体中文-"zh",法语-"fr",德语-"de"等。

    Returns:
    Type
    Promise

    convertVoiceToText(options) → {Promise}

    语音转文字的接口。音频格式支持 wav、pcm、ogg-opus、speex、silk、mp3、m4a、aac、amr。

    注意1:v3.1.3起支持。
    注意2:此功能当前处于限免阶段,您可通过即时通信 IM 功能及购买咨询交流群联系我们为您开通体验完整功能。

    Examples
    // 最常用的中英粤语音转文字,language 参数可缺省
    let promise = chat.convertVoiceToText({ message: audioMessage });
    promise.then(function(imResponse)) {
      // 语音转文字成功
      const { result } = imResponse.data;
    }).catch(function(imError) {
      // 语音转文字失败
      console.warn('convertVoiceToText error:', imError);
    });
    // 日语语音转文字
    let promise = chat.convertVoiceToText({ message: audioMessage, language: 'ja-JP'});
    promise.then(function(imResponse)) {
      // 语音转文字成功
      const { result } = imResponse.data;
    }).catch(function(imError) {
      // 语音转文字失败
      console.warn('convertVoiceToText error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    message Message required

    音频消息

    language String | undefined required

    语言类型,默认中英粤语音转文字。其它可选类型:

    • zh (cmn-Hans-CN),中文通用
    • en-US,英语
    • yue-Hant-HK,粤语
    • ja-JP,日语
    Returns:
    Type
    Promise

    setMessageExtensions(message, extensions) → {Promise}

    设置消息扩展。设置成功后,自己和对端用户(C2C)或群组成员(Group)都会收到 MESSAGE_EXTENSIONS_UPDATED 事件。

    注意1:使用该接口需要您购买旗舰版套餐。
    注意2:扩展 key 最大支持 100 字节,扩展 value 最大支持 1KB,单次最大支持设置 20 个扩展,单条消息最多可设置 300 个扩展。
    注意3:当多个用户同时设置同一个扩展 key 时,只有第一个用户可以执行成功,其它用户会收到 23001 错误码和更新后的扩展信息,在收到错误码和最新扩展信息后,请按需重新发起设置操作。
    注意4:建议不同的用户设置不同的扩展 key,这样大部分场景都不会冲突,比如投票、接龙、问卷调查,都可以把自己的 userID 作为扩展 key。
    注意5:社群和话题支持消息扩展。

    Example
    let promise = chat.setMessageExtensions(message, [{ key: 'a', value: '1' }, { key: 'b', value: '2' }]);
    promise.then(function(imResponse) {
      // 设置消息扩展成功
       const { extensions } = imResponse.data;
       extensions.forEach((item) => {
         const { code, key, value } = item;
         if (code === 23001) {
           // 设置 key 冲突,请根据返回的最新扩展信息,按需进行重试
         }
       });
    }).catch(function(imError) {
      // 设置消息扩展失败
      console.warn('setMessageExtensions error:', imError);
    });
    Parameters:
    Name Type Description
    message Message required

    消息实例,消息需要满足以下三个条件:

    • 消息的 isSupportExtension 属性必须为 true
    • 消息必须是发送成功的状态
    • 消息不能是直播群(AVChatRoom)消息
    extensions Array.<Object> required

    扩展信息

    Returns:
    Type
    Promise

    getMessageExtensions(message) → {Promise}

    获取消息扩展。

    注意1:使用该接口前,需要您购买旗舰版套餐包。
    注意2:社群和话题支持消息扩展。

    Example
    let promise = chat.getMessageExtensions(message);
    promise.then(function(imResponse) {
      // 获取消息扩展成功
       const { extensions } = imResponse.data;
       extensions.forEach((item) => {
         const { key, value } = item;
         // key - 消息扩展 key
         // value - 消息扩展 key 对应的 value 值
       });
    }).catch(function(imError) {
      // 获取消息扩展失败
      console.warn('getMessageExtensions error:', imError);
    });
    Parameters:
    Name Type Description
    message Message required

    消息实例,消息需要满足以下四个条件:

    • 消息的 isSupportExtension 属性必须为 true
    • 消息必须是发送成功的状态
    • 消息不能是已撤回的消息
    • 消息不能是直播群(AVChatRoom)消息
    Returns:
    Type
    Promise

    deleteMessageExtensions(message, keyList) → {Promise}

    删除消息扩展。删除成功后,自己和对端用户(C2C)或群组成员(Group)都会收到 MESSAGE_EXTENSIONS_DELETED 事件。

    注意1:使用该接口前,需要您购买旗舰版套餐包。
    注意2:当多个用户同时设置或删除同一个扩展 key 时,只有第一个用户可以执行成功,其它用户会收到 23001 错误码和最新的扩展信息,在收到错误码和扩展信息后,请按需重新发起删除操作。
    注意3:社群和话题支持消息扩展。

    Examples
    // 删除消息扩展 key
    let promise = chat.deleteMessageExtensions(message, ['a', 'b']);
    promise.then(function(imResponse) {
       // 删除消息扩展成功
       const { extensions } = imResponse.data;
       extensions.forEach((item) => {
         const { code, key, value } = item;
         if (code === 23001) {
           // 删除 key 冲突,请根据返回的最新扩展信息,按需进行重试
         }
       });
    }).catch(function(imError) {
      // 删除消息扩展失败
      console.warn('deleteMessageExtensions error:', imError);
    });
    // 清空所有消息扩展 key
    let promise = chat.deleteMessageExtensions(message);
    promise.then(function(imResponse) {
       // 清空消息扩展成功
       console.log('deleteMessageExtensions ok:', imResponse)
    }).catch(function(imError) {
      // 清空消息扩展失败
      console.warn('deleteMessageExtensions error:', imError);
    });
    Parameters:
    Name Type Description
    message Message required

    消息实例,消息需要满足以下三个条件:

    • 消息的 isSupportExtension 属性必须为 true
    • 消息必须是发送成功的状态
    • 消息不能是直播群(AVChatRoom)消息
    keyList Array | undefined required

    扩展信息 key 列表

    Returns:
    Type
    Promise

    addMessageReaction(message, reactionID) → {Promise}

    添加消息回应。该接口可实现“emoji 表情回应”等场景。

    注意1:v3.2.0 起支持,使用该接口需要您购买旗舰版套餐。
    注意2:如果单条消息 Reaction 数量超过最大限制(10),调用接口会返回错误码 23005。
    注意3:如果单个 Reaction 用户数量超过最大限制(100),调用接口会返回错误码 23006。
    注意4:如果 Reaction 已经包含当前用户,调用接口会返回错误吗 23007。

    Examples
    emoji 表情回应功能是指对某条消息通过表情符号进行互动回应,我们可以看到每种表情的回应人数和回应人列表。
    目前常见的消息回应展示方式会有如下两种风格:
    风格一:
     ----------------------------
     | lucy, happy birthday!  |
     ----------------------------
     | 😄 1 💐 2 👍🏻 10 |
     ----------------------------
    风格二:
     ----------------------------
     | lucy, happy birthday! |
     -----------------------------
     | 😁 bob 💐 olivia 🎂 david |
     | 👍🏻 denny、james、lucy、linda、thomas 等10人 |
     ---------------------------------------------—
    当用户点击某个表情后,会跳转到表情回应详情界面,用户可以根据某个表情分页拉取使用该表情的用户信息。
    let promise = chat.addMessageReaction(message, 'smile');
    promise.then(function(imResponse) {
      // 添加消息回应成功
    }).catch(function(imError) {
      // 添加消息回应失败
      console.warn('addMessageReaction error:', imError);
    });
    Parameters:
    Name Type Description
    message Message required

    消息实例

    reactionID String required

    消息回应 ID,在表情回应场景,reactionID 为表情 ID,单条消息最大支持 10 个 Reaction,单个 Reaction 最大支持 100 个用户。

    Returns:
    Type
    Promise

    removeMessageReaction(message, reactionID) → {Promise}

    删除消息回应。

    注意1:v3.2.0 起支持,使用该接口需要您购买旗舰版套餐。
    注意2:如果 Reaction 不存在,调用接口会返回错误码 23008 。
    注意3:如果 Reaction 不包含当前用户,调用接口会返回错误码 23009。

    Example
    let promise = chat.removeMessageReaction(message, 'smile');
    promise.then(function(imResponse) {
      // 删除消息回应成功
    }).catch(function(imError) {
      // 删除消息回应失败
      console.warn('removeMessageReaction error:', imError);
    });
    Parameters:
    Name Type Description
    message Message required

    消息实例

    reactionID String required

    消息回应 ID,在表情回应场景,reactionID 为表情 ID,单条消息最大支持 10 个 Reaction,单个 Reaction 最大支持 100 个用户。

    Returns:
    Type
    Promise

    getMessageReactions(options) → {Promise}

    批量拉取多条消息回应信息。

    注意1:v3.2.0 起支持,使用该接口需要您购买旗舰版套餐。

    Example
    let promise = chat.getMessageReactions({
      messageList: [message1, message2],
      maxUserCountPerReaction: 10,
    });
    promise.then(function(imResponse) {
      // 批量拉取成功
       const { resultList } = imResponse.data;
       resultList.forEach((item) => {
         const { messageID, reactionList } = item;
         // reactionList 返回的信息如下:
         // reactionID - 消息回应 ID
         // totalUserCount - 同一个 reactionID 回应消息的总的用户个数
         // partialUserList - 同一个 reactionID 的部分用户列表,包含用户的 userID、nick、avatar 信息
       });
    }).catch(function(imError) {
      // 批量拉取失败
      console.warn('getMessageReactions error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    messageList Array.<Message> required

    消息列表,一次最大支持 20 条消息。

    maxUserCountPerReaction Number 10

    取值范围 [0,10],每个 Reaction 最多只返回前 10 个用户信息,如需更多用户信息,可以按需调用 getAllUserListOfMessageReaction 接口分页拉取。

    Returns:
    Type
    Promise

    getAllUserListOfMessageReaction(options) → {Promise}

    分页拉取指定消息回应的用户列表。

    注意1:v3.2.0 起支持,使用该接口需要您购买旗舰版套餐。

    Example
    let promise = chat.getAllUserListOfMessageReaction({
      message: message,
      reactionID: 'smile',
      nextSeq: 0,
      count: 100,
    });
    promise.then(function(imResponse) {
      // 获取成功
      const { userList, nextSeq, isCompleted } = imResponse.data;
      // userList - 用户信息列表,包含用户的 userID、nick、avatar 信息
      // nextSeq - 用于续拉,分页续拉时需传入该字段
      // isCompleted - 表示是否已经拉完所有的用户信息。isCompleted 为 true 时,nextSeq 为 0
    }).catch(function(imError) {
      // 获取失败
      console.warn('getAllUserListOfMessageReaction error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    message Message required

    消息实例

    reactionID String required

    消息回应 ID

    nextSeq Number required

    分页拉取的起始位,第一次传 0,续拉时填入上次调用 getAllUserListOfMessageReaction 接口返回的该字段的值。

    count Number 100

    一次分页拉取的用户个数,最大支持 100 个。

    Returns:
    Type
    Promise

    modifyMessage(message) → {Promise}

    变更消息的接口。变更成功后,自己和对端用户(C2C)或群组成员(Group)都会收到 MESSAGE_MODIFIED 事件。

    注意1:不支持修改在线消息;不支持修改直播群消息;请勿修改消息的 random,sequence,time 等字段
    注意2:支持修改文本消息、自定义消息、地理位置消息和表情消息的 type,payload,cloudCustomData 字段
    注意3:如果在修改消息过程中,消息已经被其他人修改,SDK 会返回错误码2480,表示修改消息时发生冲突
    注意4:支持修改所有类型消息的 cloudCustomData 字段

    Example
    // 监听 MESSAGE_MODIFIED 事件,当修改消息成功后,SDK 会派发此事件
    let onMessageModified = function(event) {
      // event.data - 存储被修改过的 Message 对象的数组 - [Message]
    };
    chat.on(TencentCloudChat.EVENT.MESSAGE_MODIFIED, onMessageModified);
    
    // 将 txtMessage 的文本内容改为 "Hello Tencent"
    txtMessage.payload.text = "Hello Tencent";
    
    let promise = chat.modifyMessage(txtMessage);
    promise.then(function(imResponse) {
      const { message } = imResponse.data;
      // 修改消息成功,message 是最新的消息
    }).catch(function(imError) {
      // 修改消息失败
      const { code, data } = imError;
      if (code === 2480) {
        // 修改消息发生冲突,data.message 是最新的消息
      } else if (code === 2481) {
        // 不支持修改直播群消息
      } else if (code === 20026) {
        // 消息不存在
      }
    });
    Parameters:
    Name Type Description
    message Message required

    消息实例

    Returns:
    Type
    Promise

    getMessageList(options) → {Promise}

    分页拉取指定会话的消息列表的接口,当用户进入会话首次渲染消息列表或者用户“下拉查看更多消息”时,需调用该接口。

    注意1:该接口可用于"拉取历史消息"(直播群除外)。
    注意2:直播群默认不存储历史消息,当新用户进入直播间后,只能看到进入直播间后用户发送的消息。为了提升直播间用户粘性,让用户更有参与感,您可在即时通信 IM 控制台>【应用配置】>【功能配置】>【群组配置】->【直播群新成员查看入群前消息量配置】变更新成员可查看最近消息数。该功能仅支持旗舰版使用,新入群成员查看入群前 24 小时内最新产生的消息,最多可查看 20 条。
    注意3:如果您想搜索本地消息,请使用 findMessage,如果您想搜索全量的云端消息,请使用 searchCloudMessages(此功能属于增值服务,需要您购买云端搜索插件,请点击 购买

    See:
    Examples
    // 打开某个会话时,第一次拉取消息列表,注意!第一次拉取时不要传入 nextReqMessageID
    let promise = chat.getMessageList({conversationID: 'C2Ctest'});
    promise.then(function(imResponse) {
      const messageList = imResponse.data.messageList; // 消息列表。
      const nextReqMessageID = imResponse.data.nextReqMessageID; // 用于续拉,分页续拉时需传入该字段。
      const isCompleted = imResponse.data.isCompleted; // 表示是否已经拉完所有消息。isCompleted 为 true 时,nextReqMessageID 为 ""。
    });
    // 下拉查看更多消息
    let promise = chat.getMessageList({conversationID: 'C2Ctest', nextReqMessageID});
    promise.then(function(imResponse) {
      const messageList = imResponse.data.messageList; // 消息列表。
      const nextReqMessageID = imResponse.data.nextReqMessageID; // 用于续拉,分页续拉时需传入该字段。
      const isCompleted = imResponse.data.isCompleted; // 表示是否已经拉完所有消息。isCompleted 为 true 时,nextReqMessageID 为 ""。
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    conversationID String required

    会话 ID。会话 ID 组成方式:

    • C2C${userID}(单聊)
    • GROUP${groupID}(群聊)
    • GROUP${topicID}(话题)
    • @TIM#SYSTEM(系统通知会话)
    nextReqMessageID String | undefined required

    用于分页续拉的消息 ID。第一次拉取时不要传入 nextReqMessageID,续拉时填入上次调用 getMessageList 接口返回的该字段的值。

    Returns:
    Type
    Promise

    getMessageListHopping(options) → {Promise}

    根据指定的消息 sequence 或 消息时间拉取会话的消息列表的接口。

    注意1:isCompleted(拉取完成标识),nextSeq(用于群和话题续拉),nextTime(用于C2C续拉)字段
    注意2:该接口获取的漫游消息,SDK 不会缓存到本地的消息列表,消息列表按照消息发送时间由旧到新排序,单次请求 count 最大值是 15。
    注意3:拉群会话历史消息,如果不传入 sequence,direction = 0 时,默认从最新消息开始拉取。
    注意4:拉群会话历史消息,如果不传入 sequence,direction = 1 时,messageList 为空数组,且 isCompleted 为 true。
    注意5:拉单聊会话历史消息,如果不传入 time,direction = 0 时,默认从最新消息开始拉取。
    注意6:拉单聊会话历史消息,如果不传入 time,direction = 1 时,messageList 为空数组,且 isCompleted 为 true。
    注意7:如果您想搜索本地消息,请使用 findMessage,如果您想搜索全量的云端消息,请使用 searchCloudMessages(此功能属于增值服务,需要您购买云端搜索插件,请点击 购买。)

    See:
    Examples
    // 根据 sequence 拉群漫游消息,direction 0 向上拉,拉更旧的消息,direction 1 向下拉,拉更新的消息
    let promise = chat.getMessageListHopping({conversationID: 'GROUPtest', sequence: xxx, count: 15, direction: 0});
    promise.then(function(imResponse) {
      const { messageList, isCompleted, nextMessageSeq } = imResponse.data;
      // messageList - 消息列表
      // isCompleted - 拉取完成标识, true 已拉完,false 未拉完,可以通过 nextMessageSeq 的返回值进行续拉
      // nextMessageSeq - 续拉起始 sequence,当 isCompleted 返回 true 时,nextMessageSeq 返回空字符串
    });
    // 根据时间拉 C2C 会话漫游消息,direction 0 向上拉,拉更旧的消息,direction 1 向下拉,拉更新的消息
    let promise = chat.getMessageListHopping({conversationID: 'C2Ctest', time: xxx, count: 15, direction: 0});
    promise.then(function(imResponse) {
      const { messageList, isCompleted, nextMessageTime } = imResponse.data;
      // messageList - 消息列表
      // isCompleted - 拉取完成标识,true 已拉完,false 未拉完,可以通过 nextMessageTime 的返回值进行续拉
      // nextMessageTime - 续拉起始时间,当 isCompleted 返回 true 时,nextMessageTime 返回空字符串
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    conversationID String required

    会话 ID。会话 ID 组成方式:

    • C2C${userID}(单聊)
    • GROUP${groupID}(群聊)
    • GROUP${topicID}(话题)
    sequence Number required

    用于拉群组会话漫游消息的起始 sequence。

    time Number required

    消息的服务端时间,用于拉 C2C 会话漫游消息的起始时间。

    direction Number 0

    消息拉取方向,默认 0。

    • 0 向上拉,拉更旧的消息
    • 1 向下拉,拉更新的消息
    count Number 15

    需要拉取的消息数量,默认值和最大值为15。

    Returns:
    Type
    Promise

    sendMessageReadReceipt(messageList) → {Promise}

    发送消息已读回执。

    注意1:messageList 里的消息必须在同一个 C2C 或 Group 会话中。
    注意2:调用该接口成功后,会话未读数不会变化,消息发送者会收到 TencentCloudChat.TYPES.MESSAGE_READ_RECEIPT_RECEIVED 事件,回调里面会携带消息的最新已读信息。
    注意3:使用该接口需要升级到旗舰版。
    注意4:社群和直播群不支持群已读回执。
    注意5:C2C 消息调用此接口成功后,消息发送方的 message.readReceiptInfo.isPeerRead 属性会更新为 true,此属性可用于 C2C 已读回执消息状态渲染,调用此接口不会更新消息的 isPeerRead 属性。

    Examples
    // 拉取群消息列表
    let messageList = null;
    chat.getMessageList({conversationID: 'GROUPtest'}).then(function(imResponse) {
      messageList = imResponse.data.messageList; // 消息列表
      chat.sendMessageReadReceipt(messageList).then(function() {
        // 发送群消息已读回执成功
      }).catch(function(imError) {
        // 发送群消息已读回执失败
      });
    });
    // 拉取C2C消息列表
    let messageList = null;
    chat.getMessageList({conversationID: 'C2Ctest'}).then(function(imResponse) {
      messageList = imResponse.data.messageList; // 消息列表
      chat.sendMessageReadReceipt(messageList).then(function() {
        // 发送C2C消息已读回执成功
      }).catch(function(imError) {
        // 发送C2C消息已读回执失败
      });
    });
    Parameters:
    Name Type Description
    messageList Array required

    同一个 C2C 或 GROUP 会话的消息列表,最大长度为30

    Returns:
    Type
    Promise

    getMessageReadReceiptList(messageList) → {Promise}

    拉取已读回执列表。调用时机:拉取完群漫游消息后。

    注意1:messageList 里的消息必须在同一个 C2C 或 Group 会话中。
    注意2:社群不支持群已读回执。

    Examples
    // 拉取群消息列表
    let messageList = null;
    chat.getMessageList({conversationID: 'GROUPtest'}).then(function(imResponse) {
      messageList = imResponse.data.messageList; // 消息列表
      chat.getMessageReadReceiptList(messageList).then(function(imResponse) {
        messageList = imResponse.data.messageList; // 消息列表
        // 成功后,Message.readReceiptInfo 包含消息的已读回执信息
        // Message.readReceiptInfo.readCount - 消息的已读数,如果想要查询哪些群成员已读了此消息,请使用 [getGroupMessageReadMemberList] 接口
        // Message.readReceiptInfo.unreadCount - 消息的未读数,当为0的时候,表示“全部已读”。
      }).catch(function(imError) {
        // 拉取已读回执列表失败
      });
    });
    // 拉取 C2C 消息列表
    let messageList = null;
    chat.getMessageList({conversationID: 'C2Ctest'}).then(function(imResponse) {
      messageList = imResponse.data.messageList; // 消息列表
      chat.getMessageReadReceiptList(messageList).then(function(imResponse) {
        messageList = imResponse.data.messageList; // 消息列表
        // 成功后,Message.readReceiptInfo 包含消息的已读回执信息
        // Message.readReceiptInfo.isPeerRead - 对端是否已发送已读回执
      }).catch(function(imError) {
        // 拉取已读回执列表失败
      });
    });
    Parameters:
    Name Type Description
    messageList Array required

    同一群会话的消息列表

    Returns:
    Type
    Promise

    getGroupMessageReadMemberList(options) → {Promise}

    获取群消息已读(或未读)群成员列表。

    注意1:社群不支持群已读回执。

    Examples
    // 拉取群消息已读成员列表
    let promise = chat.getGroupMessageReadMemberList({
      message,
      filter: 0,
      cursor: '', // 第一次拉取传''
      count: 30,
    });
    promise.then(function(imResponse) {
      const { isCompleted, cursor, messageID, readUserIDList } = imResponse.data;
      // isCompleted - true,拉取完成;false 未完成
      // cursor - 当 isCompleted 为 false 的时候用于续拉
      // messageID - 群消息的 ID
      // readUserIDList - 已读的群成员 userID 列表。接入侧可调用 getGroupMemberProfile 接口查询群成员的资料,如群名片、头像、昵称等
    }).catch(function(imError) {
      // 拉取群消息已读群成员列表失败
    });
    // 拉取群消息未读成员列表
    let promise = chat.getGroupMessageReadMemberList({
      message,
      filter: 1,
      cursor: '', // 第一次拉取传''
      count: 30,
    });
    promise.then(function(imResponse) {
      const { isCompleted, cursor, messageID, unreadUserIDList } = imResponse.data;
      // isCompleted - true,拉取完成;false 未完成
      // cursor - 当 isCompleted 为 false 的时候用于续拉
      // messageID - 群消息的 ID
      // unreadUserIDList - 未读的群成员 userID 列表。接入侧可调用 getGroupMemberProfile 接口查询群成员的资料,如群名片、头像、昵称等
    }).catch(function(imError) {
      // 拉取群消息未读群成员列表失败
      // 10062 - 找不到群消息的已读回执信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    message Message required

    群消息

    cursor String required

    分页拉取的游标,第一次拉取传''

    filter Number required

    指定拉取已读或未读群成员列表。0 - 拉取已读成员列表;1 - 拉取未读成员列表

    count Number required

    分页拉取的个数,最大支持 100 个

    Returns:
    Type
    Promise

    findMessage(messageID) → {Message|null}

    根据 messageID 查询会话的本地消息的接口。

    注意1:该接口查询的是通过 getMessageList 存入本地的消息。
    注意2:如果您想搜索全量的云端消息,请使用 searchCloudMessages(此功能属于增值服务,需要您购买云端搜索插件,请点击 购买)。

    Example
    let message = chat.findMessage('144115217363870632-1647417469-77069006');
    if (message) {
      // 读取 message 相关属性,如已读回执信息 readReceiptInfo
    }
    Parameters:
    Name Type Description
    messageID String required

    消息 ID

    Returns:
    Type
    Message | null

    setMessageRead(options) → {Promise}

    将某会话下的未读消息状态设置为已读,置为已读的消息不会计入到未读统计,当打开会话或切换会话时调用该接口。如果在打开/切换会话时,不调用该接口,则对应的消息会一直是未读的状态。

    注意1:该接口是针对整个会话进行已读上报,调用成功后,会话的未读数(unreadCount)会被置为 0。
    注意2:如果您想实现单条或多条消息的已读通知,请参考 sendMessageReadReceipt
    注意3:如果您想将会话标为未读,请参考 markConversation

    Example
    // 将某会话下所有未读消息已读上报
    let promise = chat.setMessageRead({conversationID: 'C2Cexample'});
    promise.then(function(imResponse) {
      // 已读上报成功,指定 ID 的会话的 unreadCount 属性值被置为0
    }).catch(function(imError) {
      // 已读上报失败
      console.warn('setMessageRead error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    conversationID String required

    会话 ID。会话 ID 组成方式:

    • C2C${userID}(单聊)
    • GROUP${groupID}(群聊)
    • @TIM#SYSTEM(系统通知会话)
    • GROUP${topicID}(话题)
    Returns:
    Type
    Promise

    getConversationList(options) → {Promise}

    获取会话列表的接口。

    注意1:该接口获取的会话列表中的资料是不完整的(仅包括头像、昵称等,能够满足会话列表的渲染需求),若要查询详细会话资料,可参考:getConversationProfile
    注意2:客户端默认可从云端拉取100个最近联系人会话,升级旗舰版后可配置从云端拉取最多500个最近联系人会话。
    注意3:会话保存时长跟会话最后一条消息保存时间一致,消息默认保存7天,即会话默认保存7天。即时通信 IM 支持在控制台修改消息漫游时长,延长消息漫游时长是增值服务,具体计费说明请参考 价格说明
    注意4:支持获取指定的多个会话。
    注意5:支持根据会话类型、会话标记值、会话分组名过滤会话列表。
    注意6:该接口的返回数据字段 isSyncCompleted,用于标识从云端同步会话列表是否完成。
    注意7:登录成功后,SDK 会以【分页请求】的方式主动拉取会话列表。此接口的返回结果即为 SDK 拉取到的会话列表。如果 SDK 尚未从云端拉取到数据,调用此接口 SDK 将返回空数组。

    See:
    Examples
    // 获取全量的会话列表
    let promise = chat.getConversationList();
    promise.then(function(imResponse) {
      const conversationList = imResponse.data.conversationList; // 全量的会话列表,用该列表覆盖原有的会话列表
      const isSyncCompleted = imResponse.data.isSyncCompleted; // 从云端同步会话列表是否完成
    }).catch(function(imError) {
      console.warn('getConversationList error:', imError); // 获取会话列表失败的相关信息
    });
    // 获取指定的会话列表
    let promise = chat.getConversationList([conversationID1, conversationID2]);
    promise.then(function(imResponse) {
      const conversationList = imResponse.data.conversationList; // 缓存中已存在的指定的会话列表
    }).catch(function(imError) {
      console.warn('getConversationList error:', imError); // 获取会话列表失败的相关信息
    });
    // 获取所有的群会话
    let promise = chat.getConversationList({ type: TencentCloudChat.TYPES.CONV_GROUP });
    promise.then(function(imResponse) {
      const conversationList = imResponse.data.conversationList; // 会话列表
    });
    // 获取所有的“标星”会话
    let promise = chat.getConversationList({ markType: TencentCloudChat.TYPES.CONV_MARK_TYPE_STAR });
    promise.then(function(imResponse) {
      const conversationList = imResponse.data.conversationList; // 会话列表
    });
    // 获取所有的无标记的会话(v3.3.0起支持)
    let promise = chat.getConversationList({ markType: 0 });
    promise.then(function(imResponse) {
      const conversationList = imResponse.data.conversationList; // 会话列表
    });
    // 获取指定会话分组下的所有会话
    let promise = chat.getConversationList({ groupName: 'Suppliers' });
    promise.then(function(imResponse) {
      const conversationList = imResponse.data.conversationList; // 会话列表
    });
    // 获取不属于任何分组的会话(v3.3.0起支持)
    let promise = chat.getConversationList({ groupName: '' });
    promise.then(function(imResponse) {
      const conversationList = imResponse.data.conversationList; // 会话列表
    });
    // 获取有未读数的会话(v3.3.0起支持)
    let promise = chat.getConversationList({ hasUnreadCount: true });
    promise.then(function(imResponse) {
      const conversationList = imResponse.data.conversationList; // 会话列表
    });
    // 获取有群 @ 消息的会话(v3.3.0起支持)
    let promise = chat.getConversationList({ hasGroupAtInfo: true });
    promise.then(function(imResponse) {
      const conversationList = imResponse.data.conversationList; // 会话列表
    });
    Parameters:
    Name Type Description
    options undefined | Array | Object required

    参数选项

    • options 不传表示获取全部会话
    • options 传入数组参数表示获取指定的多个会话,如果传入空数组,则接口不返回数据
    • options 传入 { type, markType, groupName, hasUnreadCount, hasGroupAtInfo } 表示按这些条件过滤会话列表。
    Returns:
    Type
    Promise

    getConversationProfile(conversationID) → {Promise}

    获取会话资料的接口,当点击会话列表中的某个会话时,调用该接口获取会话的详细信息。

    See:
    Example
    let promise = chat.getConversationProfile(conversationID);
    promise.then(function(imResponse) {
      // 获取成功
      console.log(imResponse.data.conversation); // 会话资料
    }).catch(function(imError) {
      console.warn('getConversationProfile error:', imError); // 获取会话资料失败的相关信息
    });
    Parameters:
    Name Type Description
    conversationID String required

    会话 ID。会话 ID 组成方式:

    • C2C${userID}(单聊)
    • GROUP{groupID}(群聊)
    • @TIM#SYSTEM(系统通知会话)
    Returns:
    Type
    Promise

    deleteConversation(options) → {Promise}

    根据会话 ID 删除会话的接口。调用接口成功后 SDK 会派发事件 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED

    注意1:删除会话默认会清空会话历史消息,使用前请务必留意,如需保留会话历史消息,请将 clearHistoryMessage 设置为 false。
    注意2:删除会话默认不会多端同步,如果需要多端同步,请在即时通信 IM 控制台>【应用配置】>【功能配置】>【登录与消息】->【多端同步设置】开启【删除会话后多端同步】。
    注意3:支持批量删除会话(每次最多支持删除100个会话)。
    注意4:成员退群、群主解散群、成员被踢出群等场景下,若用户登录态未失效,则对应的群会话仍会保留在本地会话列表,此时用户可以查看已缓存的历史消息,但不能发送消息。

    Examples
    // 删除单一会话, 并清空会话历史消息
    let promise = chat.deleteConversation('C2CExample');
    promise.then(function(imResponse) {
      // 删除会话成功
      const { conversationID } = imResponse.data; // 被删除的会话 ID
    }).catch(function(imError) {
      console.warn('deleteConversation error:', imError); // 删除会话失败的相关信息
    });
    // 删除单一会话, 不清空会话历史消息
    let promise = chat.deleteConversation({conversationIDList: ['C2CExample'], clearHistoryMessage: false});
    promise.then(function(imResponse) {
      // 删除会话成功
      const { conversationIDList } = imResponse.data; // 被删除的会话 ID 列表
    }).catch(function(imError) {
      console.warn('deleteConversation error:', imError); // 删除会话失败的相关信息
    });
    // 删除多个会话, 并清空会话历史消息
    let promise = chat.deleteConversation({conversationIDList: ['C2CExample', 'GROUPExample']});
    promise.then(function(imResponse) {
      // 删除会话成功
      const { conversationIDList } = imResponse.data; // 被删除的会话 ID 列表
    }).catch(function(imError) {
      console.warn('deleteConversation error:', imError); // 删除会话失败的相关信息
    });
    // 删除多个会话, 不清空会话历史消息
    let promise = chat.deleteConversation({conversationIDList: ['C2CExample', 'GROUPExample'], clearHistoryMessage: false});
    promise.then(function(imResponse) {
      // 删除会话成功
      const { conversationIDList } = imResponse.data; // 被删除的会话 ID 列表
    }).catch(function(imError) {
      console.warn('deleteConversation error:', imError); // 删除会话失败的相关信息
    });
    Parameters:
    Name Type Description
    options String | Object required

    参数选项, 当类型为 String 时, 表示为: 会话 ID 会话 ID 组成方式:

    • C2C${userID}(单聊)
    • GROUP${groupID}(群聊)
    • @TIM#SYSTEM(系统通知会话)
    Properties
    Name Type Default Description
    conversationIDList Array.<String> required

    会话ID列表

    clearHistoryMessage Boolean true

    是否清空会话历史消息, 默认 true。

    • true 清空会话历史消息
    • false 不清空会话历史消息
    Returns:
    Type
    Promise

    setConversationDraft(options) → {Promise}

    设置会话草稿。

    注意1:v3.1.1起支持。
    注意2:草稿只在 SDK 运行期间保存,不会存储 Server,不能多端同步。

    Examples
    // 设置会话草稿
    let promise = chat.setConversationDraft({
       conversationID: 'GROUPpublic1',
       draftText: '123'
    });
    promise.then(function(imResponse) {
      // 设置会话草稿成功
    }).catch(function(imError) {
      console.warn('setConversationDraft error:', imError); // 设置会话草稿失败
    });
    // 取消会话草稿
    let promise = chat.setConversationDraft({
       conversationID: 'GROUPpublic1',
       draftText: ''
    });
    promise.then(function(imResponse) {
      // 取消 GROUPpublic1 会话草稿成功
    }).catch(function(imError) {
      console.warn('setConversationDraft error:', imError); // 取消会话草稿失败
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    conversationID String required

    会话 ID。会话 ID 组成方式:

    • C2C${userID}(单聊)
    • GROUP${groupID}(群聊)
    draftText String required

    草稿内容, 传 '' 时,表示取消草稿。

    Returns:
    Type
    Promise

    clearHistoryMessage(conversationID) → {Promise}

    清空单聊或群聊本地及云端的消息(不删除会话)。

    注意1:会话消息被清空后,unreadCount 被置为 0,lastMessage 的内容同时被清空。
    注意2:此接口不支持清空话题(Topic)的消息。

    Examples
    // 清空单聊的本地及云端的消息
    let promise = chat.clearHistoryMessage('C2CExample');
    promise.then(function(imResponse) {
      // 清空消息成功
    }).catch(function(imError) {
      console.warn('clearHistoryMessage error:', imError); // 清空消息失败的相关信息
    });
    // 清空群聊的本地及云端的消息
    let promise = chat.clearHistoryMessage('GROUPExample');
    promise.then(function(imResponse) {
      // 清空消息成功
    }).catch(function(imError) {
      console.warn('clearHistoryMessage error:', imError); // 清空消息失败的相关信息
    });
    Parameters:
    Name Type Description
    conversationID String required

    会话 ID。会话 ID 组成方式:

    • C2C${userID}(单聊)
    • GROUP${groupID}(群聊)
    • @TIM#SYSTEM(系统通知会话)
    Returns:
    Type
    Promise

    pinConversation(options) → {Promise}

    置顶或取消置顶会话的接口。调用接口成功后会话列表重新排序,SDK 会派发事件 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED

    Examples
    // 置顶会话
    let promise = chat.pinConversation({ conversationID: 'C2CExample', isPinned: true });
    promise.then(function(imResponse) {
      // 置顶会话成功
      const { conversationID } = imResponse.data; // 被置顶的会话 ID
    }).catch(function(imError) {
      console.warn('pinConversation error:', imError); // 置顶会话失败的相关信息
    });
    // 取消置顶会话
    let promise = chat.pinConversation({ conversationID: 'C2CExample', isPinned: false });
    promise.then(function(imResponse) {
      // 取消置顶会话成功
      const { conversationID } = imResponse.data; // 被取消置顶的会话 ID
    }).catch(function(imError) {
      console.warn('pinConversation error:', imError); // 取消置顶会话失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    conversationID String required

    会话 ID。会话 ID 组成方式:

    • C2C${userID}(单聊)
    • GROUP${groupID}(群聊)
    isPinned Boolean required

    true 表示置顶会话,false 表示取消置顶会话

    Returns:
    Type
    Promise

    setAllMessageRead(options) → {Promise}

    将所有会话的未读消息设置为已读

    注意1:该接口不支持社群和话题。

    Examples
    // 将所有会话的未读消息全部设置为已读
    let promise = chat.setAllMessageRead(); // 等同于 chat.setAllMessageRead({scope: TencentCloudChat.TYPES.READ_ALL_MSG})
    promise.then(function(imResponse) {
      // 已读上报成功,所有会话的 unreadCount 属性值被置为0
    }).catch(function(imError) {
      // 已读上报失败
      console.warn('setAllMessageRead error:', imError);
    });
    // 将所有 C2C 会话的未读消息全部设置为已读
    let promise = chat.setAllMessageRead({scope: TencentCloudChat.TYPES.READ_ALL_C2C_MSG});
    promise.then(function(imResponse) {
      // 已读上报成功,所有 C2C 会话的 unreadCount 属性值被置为0
    }).catch(function(imError) {
      // 已读上报失败
      console.warn('setAllMessageRead error:', imError);
    });
    // 将所有群会话的未读消息全部设置为已读
    let promise = chat.setAllMessageRead({scope: TencentCloudChat.TYPES.READ_ALL_GROUP_MSG});
    promise.then(function(imResponse) {
      // 已读上报成功,所有 C2C 会话的 unreadCount 属性值被置为0
    }).catch(function(imError) {
      // 已读上报失败
      console.warn('setAllMessageRead error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    scope string required

    设置消息处理的范围。详细类型如下:

    • TencentCloudChat.TYPES.READ_ALL_C2C_MSG (设置所有 C2C 会话未读消息为已读)
    • TencentCloudChat.TYPES.READ_ALL_GROUP_MSG (设置所有群会话未读消息为已读)
    • TencentCloudChat.TYPES.READ_ALL_MSG (默认值,设置所有 C2C 和群会话未读消息为已读)
    Returns:
    Type
    Promise

    setMessageRemindType(options) → {Promise}

    设置会话消息提醒类型,您可以使用此接口实现“消息免打扰”,“拒收消息”的功能。

    注意1:作为群成员,设置自己所在群的消息提示类型。
    注意2:“消息免打扰”,一般的实现是在线接收消息,离线不接收消息(在有离线推送的情况下)。
    注意3:“拒收消息”,即在线和离线都不接收消息,对端发送的消息可通过 getMessageList 获取到。
    注意4:支持设置社群话题的消息提示类型,groupID 传入 topicID 即可,如果话题所属社群设置为 TencentCloudChat.TYPES.MSG_REMIND_DISCARD,则会忽略话题的设置。
    注意5:支持群会话消息和话题消息的提醒类型多终端、多实例同步。
    注意6:v3.3.2 起支持群 @消息 提示类型。

    Examples
    // 拒收群消息(通过 getMessageList 接口可拉取到其他群成员发送的消息)
    let promise = chat.setMessageRemindType({ groupID: 'group1', messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_DISCARD });
    promise.then(function(imResponse) {
      // 设置成功后 SDK 会触发 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED 事件(遍历列表,并读取 Conversation.messageRemindType)
    }).catch(function(imError) {
      console.warn('setMessageRemindType error:', imError);
    });
    // 拒收群消息后,重新开启新消息提醒
    let promise = chat.setMessageRemindType({ groupID: 'group1', messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_AND_NOTE });
    promise.then(function(imResponse) {
      // 设置成功后 SDK 会触发 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED 事件(遍历列表,并读取 Conversation.messageRemindType)
    }).catch(function(imError) {
      console.warn('setMessageRemindType error:', imError);
    });
    // C2C 消息免打扰,一般的实现是在线接收消息,离线不接收消息(在有离线推送的情况下)
    let promise = chat.setMessageRemindType({ userIDList: ['user1', 'user2'], messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE });
    promise.then(function(imResponse) {
      // 设置成功后 SDK 会触发 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED 事件(遍历列表,并读取 Conversation.messageRemindType)
      const { successUserIDList, failureUserIDList } = imResponse.data;
      // 删除成功的 userIDList
      successUserIDList.forEach((item) => {
        const { userID } = item;
      });
      // 删除失败的 userIDList
      failureUserIDList.forEach((item) => {
        const { userID, code, message } = item;
      });
    }).catch(function(imError) {
      console.warn('setMessageRemindType error:', imError);
    });
    // 群消息免打扰,一般的实现是在线接收消息,离线不接收消息(在有离线推送的情况下)
    let promise = chat.setMessageRemindType({ groupID: 'group1', messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE });
    promise.then(function(imResponse) {
      // 设置消息免打扰成功
    }).catch(function(imError) {
      // 设置消息免打扰失败
      console.warn('setMessageRemindType error:', imError);
    });
    // 社群话题消息免打扰,一般的实现是在线接收消息,离线不接收消息(在有离线推送的情况下)
    let promise = chat.setMessageRemindType({ groupID: 'topicID', messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE });
    promise.then(function(imResponse) {
      // 设置消息免打扰成功
    }).catch(function(imError) {
      // 设置消息免打扰失败
      console.warn('setMessageRemindType error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群 ID 或 话题 ID

    userIDList Array required

    C2C 会话对端 userID 列表,单次请求的 userID 数不得超过30

    messageRemindType String required

    群消息提示类型。详细如下:

    • TencentCloudChat.TYPES.MSG_REMIND_ACPT_AND_NOTE(SDK 接收消息并通知接入侧(抛出 收到消息事件),接入侧做提示)
    • TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE(SDK 接收消息并通知接入侧(抛出 收到消息事件),接入侧不做提示,一般用于实现“消息免打扰”)
    • TencentCloudChat.TYPES.MSG_REMIND_DISCARD(SDK 拒收消息)
    • TencentCloudChat.TYPES.RECEIVE_WITH_OFFLINE_PUSH_EXCEPT_AT(SDK 接收消息并通知接入侧(抛出 收到消息事件),接入侧仅对群 @消息 做提示)
    Returns:
    Type
    Promise

    setAllReceiveMessageOpt(options) → {Promise}

    设置全局消息免打扰选项

    注意1:v3.3.0 起支持。
    注意2:当 isRepeated 设置为 true 且 duration 的取值小于 246060 时,可用于实现重复免打扰,即消息免打扰从每天的 startHour:startMinute:startSecond 表示的时间点开始,持续时长为 druation 秒。
    注意3:当 isRepeated 设置为 true 且 duration 的取值大于等于 246060 时,可用于实现永久免打扰,即从调用该 API 当天 startHour:startMinute:startSecond 表示的时间点开始,永久消息免打扰。
    注意4:当 isRepeated 设置为 false 时,消息免打扰从调用该 API 当天 startHour:startMinute:startSecond 表示的时间点开始,持续时长为 druation 秒。
    注意5: 全局和会话免打扰同时设置时,全局免打扰优先级高于会话免打扰。

    Examples
    // 设置每天晚上 22 点到第二天早上 10 点重复免打扰
    let promise = chat.setAllReceiveMessageOpt({
      messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE,
      startHour: 22,
      startMinute: 0,
      startSecond: 0,
      duration: 12 * 60 * 60,
      isRepeated: true
    });
    promise.then(function(imResponse) {
      // 设置全局消息免打扰成功
    }).catch(function(imError) {
      // 设置全局消息免打扰失败
      console.warn('setAllReceiveMessageOpt error:', imError);
    });
    // 设置从当天晚上 22 点开始永久免打扰
    let promise = chat.setAllReceiveMessageOpt({
      messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE,
      startHour: 22,
      startMinute: 0,
      startSecond: 0,
      duration: 24 * 60 * 60,
      isRepeated: true
    });
    promise.then(function(imResponse) {
      // 设置全局消息免打扰成功
    }).catch(function(imError) {
      // 设置全局消息免打扰失败
      console.warn('setAllReceiveMessageOpt error:', imError);
    });
    // 设置从当天晚上 22 点到第二天早上 8 点消息免打扰(生效一次)
    let promise = chat.setAllReceiveMessageOpt({
      messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE,
      startHour: 22,
      startMinute: 0,
      startSecond: 0,
      duration: 10 * 60 * 60,
      isRepeated: false
    });
    promise.then(function(imResponse) {
      // 设置全局消息免打扰成功
    }).catch(function(imError) {
      // 设置全局消息免打扰失败
      console.warn('setAllReceiveMessageOpt error:', imError);
    });
    // 取消全局消息免打扰
    let promise = chat.setAllReceiveMessageOpt({ messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_AND_NOTE });
    promise.then(function(imResponse) {
      // 取消全局消息免打扰成功
    }).catch(function(imError) {
      // 取消全局消息免打扰失败
      console.warn('setAllReceiveMessageOpt error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    全局免打扰选项

    Properties
    Name Type Default Description
    messageRemindType String TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE
    • TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE(SDK 接收消息并通知接入侧(抛出 收到消息事件),接入侧不做提示,用户在线正常推送消息,App 离线不会有推送通知,用于实现“全局免打扰”)
    • TencentCloudChat.TYPES.MSG_REMIND_ACPT_AND_NOTE(SDK 接收消息并通知接入侧(抛出 收到消息事件),接入侧做提示,用户在线正常推送消息,App 离线会有推送通知,用于实现“取消全局免打扰”)
    startHour Number 0

    免打扰开始时间:小时,取值范围[0 - 23]

    startMinute Number 0

    免打扰开始时间:分钟,取值范围[0 - 59]

    startSecond Number 0

    免打扰开始时间:秒,取值范围[0 - 59]

    duration Number 0

    免打扰持续时长,单位:秒

    isRepeated Boolean true

    是否每天重复生效

    Returns:
    Type
    Promise

    getAllReceiveMessageOpt() → {Promise}

    获取全局消息免打扰选项

    Example
    // 获取全局消息免打扰选项
    let promise = chat.getAllReceiveMessageOpt();
    promise.then(function(imResponse) {
      // 获取全局消息免打扰选项成功
      const { messageRemindType, startTime, endTime, isRepeated } = imResponse.data;
      // messageRemindType - 消息免打扰类型
      // startTime - 消息免打扰开始时间, UNIX 时间戳
      // endTime - 消息免打扰结束时间, UNIX 时间戳
      // isRepeated - 是否每天重复生效
    }).catch(function(imError) {
      // 获取全局消息免打扰选项失败
      console.warn('getAllReceiveMessageOpt error:', imError);
    });
    Returns:
    Type
    Promise

    getTotalUnreadMessageCount() → {Number}

    获取会话未读总数。接入侧可以通过监听 TOTAL_UNREAD_MESSAGE_COUNT_UPDATED 事件获取会话未读总数变更。

    注意1:未读总数会减去设置为免打扰的会话的未读数。
    注意2:未读总数不计算系统会话的未读数。
    注意3:因为该接口依赖 SDK 从云端同步会话列表,所以登录成功后立即调用该接口获取到的未读总数可能为 0,接入侧可以结合 TOTAL_UNREAD_MESSAGE_COUNT_UPDATED 事件更新本地的未读总数。

    Example
    // 获取单聊和群聊会话的未读总数
    let totalUnreadCount = chat.getTotalUnreadMessageCount();
    Returns:
    Type
    Number

    setConversationCustomData(options) → {Promise}

    设置会话自定义数据。调用接口成功后 SDK 会派发事件 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED

    Examples
    // 给 C2C 会话和群会话设置会话自定义数据
    let promise = chat.setConversationCustomData({
      conversationIDList: ['GROUPtest', 'C2Cexample'],
      customData: 'your custom data'
    });
    promise.then(function(imResponse) {
      // 设置会话自定义数据成功
      const { successConversationIDList, failureConversationIDList } = imResponse.data;
      // successConversationIDList - 设置成功的会话 ID 列表
      // 获取会话列表
      const conversationList = chat.getConversationList(successConversationIDList);
    
      // failureConversationIDList - 设置失败的会话 ID 列表
      failureConversationIDList.forEach((item) => {
        const { conversationID, code, message } = item;
      });
    }).catch(function(imError) {
      console.warn('setConversationCustomData error:', imError);
    });
    // customData 传入空字符串,表示清空会话自定义数据
    let promise = chat.setConversationCustomData({
      conversationIDList: ['GROUPtest', 'C2Cexample'],
      customData: ''
    });
    promise.then(function(imResponse) {
      // 清空会话自定义数据成功
      const { successConversationIDList, failureConversationIDList } = imResponse.data;
      // successConversationIDList - 清空成功的会话 ID 列表
      // 获取会话列表
      const conversationList = chat.getConversationList(successConversationIDList);
    
      // failureConversationIDList - 清空失败的会话 ID 列表
      failureConversationIDList.forEach((item) => {
        const { conversationID, code, message } = item;
      });
    }).catch(function(imError) {
      console.warn('setConversationCustomData error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    conversationIDList Array required

    会话 ID 列表

    customData String required

    自定义数据,长度最大支持256字节

    Returns:
    Type
    Promise

    markConversation(options) → {Promise}

    标记会话,调用接口成功后 SDK 会派发事件 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED
    SDK 支持以下标记值:

    如果已有的标记不能满足您的需求,您可以自定义标记,自定义标记需要满足以下两个条件:
    1、自定义标记值不能和 SDK 已有的标记值冲突。
    2、自定义标记值必须是 Math.power(2, n)(32 <= n < 64,即 n 必须大于等于 32 并且小于 64),比如自定义 Math.power(2, 32) 标记值表示 "iPhone 在线"。

    注意1:使用该接口需要您购买旗舰版套餐。

    Examples
    // 会话标星
    let promise = chat.markConversation({
      conversationIDList: ['GROUPtest', 'C2Cexample'],
      markType: TencentCloudChat.TYPES.CONV_MARK_TYPE_STAR,
      enableMark: true
    });
    promise.then(function(imResponse) {
      // 会话标星成功
      const { successConversationIDList, failureConversationIDList } = imResponse.data;
      // successConversationIDList - 标星成功的会话 ID 列表
      // 获取会话列表
      const conversationList = chat.getConversationList(successConversationIDList);
    
      // failureConversationIDList - 标星失败的会话 ID 列表
      failureConversationIDList.forEach((item) => {
        const { conversationID, code, message } = item;
      });
    }).catch(function(imError) {
      console.warn('markConversation error:', imError);
    });
    // 获取所有标星的会话
    let promise = chat.getConversationList({ markType: TencentCloudChat.TYPES.CONV_MARK_TYPE_STAR });
    promise.then(function(imResponse) {
      const conversationList = imResponse.data.conversationList; // 会话列表
    });
    // 获取所有折叠的 C2C 会话
    let promise = chat.getConversationList({
      markType: TencentCloudChat.TYPES.CONV_MARK_TYPE_FOLD,
      type: TencentCloudChat.TYPES.CONV_C2C
    });
    promise.then(function(imResponse) {
      const conversationList = imResponse.data.conversationList; // 会话列表
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    conversationIDList Array required

    会话 ID 列表

    markType Number required

    会话标记类型

    enableMark Boolean required

    true 设置标记,false 取消标记

    Returns:
    Type
    Promise

    getConversationGroupList() → {Promise}

    获取会话分组列表。

    注意1:使用该接口需要升级到旗舰版。

    Examples
    let promise = chat.getConversationGroupList();
    promise.then(function(imResponse) {
      const groupNameList = imResponse.data; // 会话分组名列表
    });
    // 获取指定会话分组下的所有会话
    let promise = chat.getConversationList({ groupName: 'Suppliers' });
    promise.then(function(imResponse) {
      const conversationList = imResponse.data.conversationList; // 会话列表
    });
    Returns:
    Type
    Promise

    createConversationGroup(options) → {Promise}

    创建会话分组。调用接口成功后 SDK 会派发事件 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATEDTencentCloudChat.EVENT.CONVERSATION_GROUP_LIST_UPDATED

    注意1:使用该接口需要您购买旗舰版套餐。

    Example
    let promise = chat.createConversationGroup({
      conversationIDList: ['GROUPtest', 'C2Cexample'],
      groupName: 'Suppliers',
    });
    promise.then(function(imResponse) {
      // 创建会话分组成功
      const { successConversationIDList, failureConversationIDList } = imResponse.data;
      // successConversationIDList - 成功的会话 ID 列表
      // 获取会话列表
      const conversationList = chat.getConversationList(successConversationIDList);
    
      // failureConversationIDList - 失败的会话 ID 列表
      failureConversationIDList.forEach((item) => {
        const { conversationID, code, message } = item;
      });
    }).catch(function(imError) {
      console.warn('createConversationGroup error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    conversationIDList Array required

    会话 ID 列表

    groupName String required

    分组名,长度最大支持32字节

    Returns:
    Type
    Promise

    deleteConversationGroup(groupName) → {Promise}

    删除会话分组。调用接口成功后 SDK 会派发事件 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATEDTencentCloudChat.EVENT.CONVERSATION_GROUP_LIST_UPDATED

    注意1:使用该接口需要您购买旗舰版套餐。

    Example
    let promise = chat.deleteConversationGroup('Suppliers');
    promise.then(function() {
      // 删除成功
    }).catch(function(imError) {
      console.warn('deleteConversationGroup error:', imError);
    });
    Parameters:
    Name Type Description
    groupName String required

    会话分组名

    Returns:
    Type
    Promise

    renameConversationGroup(options) → {Promise}

    重命名会话分组。调用接口成功后 SDK 会派发事件 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATEDTencentCloudChat.EVENT.CONVERSATION_GROUP_LIST_UPDATED

    注意1:使用该接口需要升级到旗舰版。

    Example
    let promise = chat.renameConversationGroup({
      oldName: 'Suppliers_old',
      newName: 'Suppliers_new'
    });
    promise.then(function(imResponse) {
      // 重命名成功
    }).catch(function(imError) {
      console.warn('renameConversationGroup error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    oldName String required

    旧的分组名

    newName String required

    新的分组名,长度最大支持32字节

    Returns:
    Type
    Promise

    addConversationsToGroup(options) → {Promise}

    添加会话到一个会话分组。调用接口成功后 SDK 会派发事件 TencentCloudChat.EVENT.CONVERSATION_IN_GROUP_UPDATED

    注意1:使用该接口需要升级到旗舰版。

    Example
    let promise = chat.addConversationsToGroup({
      conversationIDList: ['GROUPtest', 'C2Cexample'],,
      groupName: 'Suppliers_new',
    });
    promise.then(function(imResponse) {
      // 添加会话到分组成功
      const { successConversationIDList, failureConversationIDList } = imResponse.data;
      // successConversationIDList - 成功的会话 ID 列表
      // 获取会话列表
      const conversationList = chat.getConversationList(successConversationIDList);
    
      // failureConversationIDList - 失败的会话 ID 列表
      failureConversationIDList.forEach((item) => {
        const { conversationID, code, message } = item;
      });
    }).catch(function(imError) {
      console.warn('addConversationsToGroup error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    conversationIDList Array required

    会话 ID 列表

    groupName String required

    分组名

    Returns:
    Type
    Promise

    deleteConversationsFromGroup(options) → {Promise}

    从一个会话分组中删除会话。调用接口成功后 SDK 会派发事件 TencentCloudChat.EVENT.CONVERSATION_IN_GROUP_UPDATED

    注意1:使用该接口需要您购买旗舰版套餐。

    Example
    let promise = chat.deleteConversationsFromGroup({
      conversationIDList: ['GROUPtest', 'C2Cexample'],,
      groupName: 'Suppliers_new',
    });
    promise.then(function(imResponse) {
      // 从分组删除会话成功
      const { successConversationIDList, failureConversationIDList } = imResponse.data;
      // successConversationIDList - 成功的会话 ID 列表
      // 获取会话列表
      const conversationList = chat.getConversationList(successConversationIDList);
    
      // failureConversationIDList - 失败的会话 ID 列表
      failureConversationIDList.forEach((item) => {
        const { conversationID, code, message } = item;
      });
    }).catch(function(imError) {
      console.warn('deleteConversationsFromGroup error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    conversationIDList Array required

    会话 ID 列表

    groupName String required

    分组名

    Returns:
    Type
    Promise

    getMyProfile() → {Promise}

    获取个人资料

    See:
    • 资料结构描述
    Example
    let promise = chat.getMyProfile();
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 个人资料 - Profile 实例
    }).catch(function(imError) {
      console.warn('getMyProfile error:', imError); // 获取个人资料失败的相关信息
    });
    Returns:
    Type
    Promise

    getUserProfile(options) → {Promise}

    获取其他用户资料。此接口会同时获取标配资料和自定义资料,详细请参考 https://cloud.tencent.com/document/product/269/1500#.E8.B5.84.E6.96.99.E7.B3.BB.E7.BB.9F.E7.AE.80.E4.BB.8B

    注意1:如果您没有配置自定义资料字段,或者配置了自定义资料字段,但是没有设置 value,此接口将不会返回自定义资料的内容。
    注意2:每次拉取的用户数不超过100,避免因回包数据量太大导致回包失败。如果传入的数组长度大于100,则只取前100个用户进行查询,其余丢弃。

    Example
    let promise = chat.getUserProfile({
      userIDList: ['user1', 'user2'] // 请注意:即使只拉取一个用户的资料,也需要用数组类型,例如:userIDList: ['user1']
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 存储用户资料的数组 - [Profile]
    }).catch(function(imError) {
      console.warn('getUserProfile error:', imError); // 获取其他用户资料失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    搜索参数

    Properties
    Name Type Description
    userIDList Array.<String> required

    用户的账号列表,类型为数组

    Returns:
    Type
    Promise

    updateMyProfile(options) → {Promise}

    更新个人资料

    Examples
    // 修改个人标配资料
    let promise = chat.updateMyProfile({
      nick: '我的昵称',
      avatar: 'http(s)://url/to/image.jpg',
      gender: TencentCloudChat.TYPES.GENDER_MALE,
      selfSignature: '我的个性签名',
      allowType: TencentCloudChat.TYPES.ALLOW_TYPE_ALLOW_ANY
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 更新资料成功
    }).catch(function(imError) {
      console.warn('updateMyProfile error:', imError); // 更新资料失败的相关信息
    });
    // 修改个人自定义资料
    // 自定义资料字段需要预先在控制台配置,详细请参考:https://cloud.tencent.com/document/product/269/1500#.E8.87.AA.E5.AE.9A.E4.B9.89.E8.B5.84.E6.96.99.E5.AD.97.E6.AE.B5
    let promise = chat.updateMyProfile({
      // 这里要求您已在即时通信 IM 控制台>【应用配置】>【功能配置】 申请了自定义资料字段 Tag_Profile_Custom_Test1
      // 注意!即使只有一个自定义资料字段,profileCustomField 也需要用数组类型
      profileCustomField: [
        {
          key: 'Tag_Profile_Custom_Test1',
          value: '我的自定义资料1'
        }
      ]
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 更新资料成功
    }).catch(function(imError) {
      console.warn('updateMyProfile error:', imError); // 更新资料失败的相关信息
    });
    // 修改个人标配资料和自定义资料
    let promise = chat.updateMyProfile({
      nick: '我的昵称',
      // 这里要求您已在即时通信 IM 控制台>【应用配置】>【功能配置】 申请了自定义资料字段 Tag_Profile_Custom_Test1 和 Tag_Profile_Custom_Test2
      profileCustomField: [
        {
          key: 'Tag_Profile_Custom_Test1',
          value: '我的自定义资料1'
        },
        {
          key: 'Tag_Profile_Custom_Test2',
          value: '我的自定义资料2'
        },
      ]
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 更新资料成功
    }).catch(function(imError) {
      console.warn('updateMyProfile error:', imError); // 更新资料失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    资料参数

    Properties
    Name Type Description
    nick String required

    昵称

    avatar String required

    头像地址

    gender String required

    性别:

    • TencentCloudChat.TYPES.GENDER_UNKNOWN(未设置性别)
    • TencentCloudChat.TYPES.GENDER_FEMALE(女)
    • TencentCloudChat.TYPES.GENDER_MALE(男)
    selfSignature String required

    个性签名

    allowType String required

    当被加人加好友时:

    • TencentCloudChat.TYPES.ALLOW_TYPE_ALLOW_ANY(允许直接加为好友)
    • TencentCloudChat.TYPES.ALLOW_TYPE_NEED_CONFIRM(需要验证)
    • TencentCloudChat.TYPES.ALLOW_TYPE_DENY_ANY(拒绝)
    birthday Number required

    生日 推荐用法:20000101

    location String required

    所在地 推荐用法:App 本地定义一套数字到地名的映射关系 后台实际保存的是4个 uint32_t 类型的数字: 其中第一个 uint32_t 表示国家; 第二个 uint32_t 用于表示省份; 第三个 uint32_t 用于表示城市; 第四个 uint32_t 用于表示区县

    language Number required

    语言

    messageSettings Number required

    消息设置 0:接收消息,1:不接收消息

    adminForbidType String required

    管理员禁止加好友标识:

    • TencentCloudChat.TYPES.FORBID_TYPE_NONE(默认值,允许加好友)
    • TencentCloudChat.TYPES.FORBID_TYPE_SEND_OUT(禁止该用户发起加好友请求)
    level Number required

    等级 建议拆分以保存多种角色的等级信息

    role Number required

    角色 建议拆分以保存多种角色信息

    profileCustomField Array.<Object> required

    自定义资料键值对集合,可根据业务侧需要使用,详细请参考: https://cloud.tencent.com/document/product/269/1500#.E8.87.AA.E5.AE.9A.E4.B9.89.E8.B5.84.E6.96.99.E5.AD.97.E6.AE.B5

    Returns:
    Type
    Promise

    getBlacklist() → {Promise}

    获取我的黑名单列表

    Example
    let promise = chat.getBlacklist();
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 我的黑名单列表,结构为包含用户 userID 的数组 - [userID]
    }).catch(function(imError) {
      console.warn('getBlacklist error:', imError); // 获取黑名单列表失败的相关信息
    });
    Returns:
    Type
    Promise

    addToBlacklist(options) → {Promise}

    添加用户到黑名单列表。将用户加入黑名单后可以屏蔽来自 TA 的所有消息,因此该接口可以实现“屏蔽该用户消息”的功能。

    • 如果用户 A 与用户 B 之间存在好友关系,拉黑时会解除双向好友关系。
    • 如果用户 A 与用户 B 之间存在黑名单关系,二者之间无法发起会话。
    • 如果用户 A 与用户 B 之间存在黑名单关系,二者之间无法发起加好友请求。

    注意1:黑名单列表上限1000,且不可调整。

    Example
    let promise = chat.addToBlacklist({userIDList: ['user1', 'user2']}); // 请注意:即使只添加一个用户账号到黑名单,也需要用数组类型,例如:userIDList: ['user1']
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 被拉黑的全量账号列表,结构为包含用户 userID 的数组 - [userID]
    }).catch(function(imError) {
      console.warn('addToBlacklist error:', imError); // 添加用户到黑名单列表失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    userIDList Array.<String> required

    待添加为黑名单的用户 userID 列表,单次请求的 userID 数不得超过1000

    Returns:
    Type
    Promise

    removeFromBlacklist(options) → {Promise}

    从黑名单列表中移除,即解除拉黑。

    Example
    let promise = chat.removeFromBlacklist({userIDList: ['user1', 'user2']}); // 请注意:即使只从黑名单中移除一个用户账号,也需要用数组类型,例如:userIDList: ['user1']
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 被拉黑的全量账号列表,结构为包含用户 userID 的数组 - [userID]
    }).catch(function(imError) {
      console.warn('removeFromBlacklist error:', imError); // 将用户从黑名单中移除失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    userIDList Array.<String> required

    待从黑名单中移除的 userID 列表,单次请求的 userID 数不得超过1000

    Returns:
    Type
    Promise

    setSelfStatus(options) → {Promise}

    设置自己的自定义状态。设置成功后,SDK 会派发 TencentCloudChat.EVENT.USER_STATUS_UPDATED 事件。

    注意1:该接口仅支持设置用户自己的自定义状态。
    注意2:使用该接口不需要升级到旗舰版,也不需要开启控制台开关。

    Example
    // 设置 customStatus 为空字符串 '',则清除自己的自定义状态
    let promise = chat.setSelfStatus({customStatus: 'xxx'});
    promise.then(function(imResponse) {
      console.log(imResponse.data);
      const { userID, statusType, customStatus } = imResponse.data;
      // userID - 用户 ID
      // statusType - 用户状态,枚举值及说明如下:
      // TencentCloudChat.TYPES.USER_STATUS_UNKNOWN - 未知
      // TencentCloudChat.TYPES.USER_STATUS_ONLINE - 在线
      // TencentCloudChat.TYPES.USER_STATUS_OFFLINE - 离线
      // TencentCloudChat.TYPES.USER_STATUS_UNLOGINED - 未登录
      // customStatus - 用户自定义状态
    }).catch(function(imError) {
      console.warn('setSelfStatus error:', imError); // 设置用户自己的自定义状态失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    customStatus String required

    用户自定义状态

    Returns:
    Type
    Promise

    getUserStatus(options) → {Promise}

    查询用户状态。

    注意1:查询自己的状态不限制旗舰版,接口调用不限频。
    注意2:查询其他用户的状态需要升级旗舰版,接口调用默认限制 5 秒 20 次请求。

    Examples
    // 查询自己的用户状态
    // userIDList 仅包含自己的 userID 时表示查询自己的状态
    let promise = chat.getUserStatus({userIDList: [`${myUserID}`]});
    promise.then(function(imResponse) {
       const { successUserList } = imResponse.data;
       successUserList.forEach((item) => {
         const { userID, statusType, customStatus } = item;
         // userID - 用户 ID
         // statusType - 用户状态,枚举值及说明如下:
         // TencentCloudChat.TYPES.USER_STATUS_UNKNOWN - 未知
         // TencentCloudChat.TYPES.USER_STATUS_ONLINE - 在线
         // TencentCloudChat.TYPES.USER_STATUS_OFFLINE - 离线
         // TencentCloudChat.TYPES.USER_STATUS_UNLOGINED - 未登录
         // customStatus - 用户自定义状态
       });
    }).catch(function(imError) {
      console.warn('getUserStatus error:', imError); // 获取用户状态失败的相关信息
    });
    // 查询其他用户的状态
    let promise = chat.getUserStatus({userIDList: ['user0', 'user1']});
    promise.then(function(imResponse) {
       const { successUserList, failureUserList } = imResponse.data;
       // 查询成功的用户列表
       successUserList.forEach((item) => {
         const { userID, statusType, customStatus } = item;
         // userID - 用户 ID
         // statusType - 用户状态,枚举值及说明如下:
         // TencentCloudChat.TYPES.USER_STATUS_UNKNOWN - 未知
         // TencentCloudChat.TYPES.USER_STATUS_ONLINE - 在线
         // TencentCloudChat.TYPES.USER_STATUS_OFFLINE - 离线
         // TencentCloudChat.TYPES.USER_STATUS_UNLOGINED - 未登录
         // customStatus - 用户自定义状态
       });
    
       // 查询失败的用户列表
       failureUserList.forEach((item) => {
         const { userID, code, message } = item;
         // userID - 查询失败的用户 ID
         // code - 查询失败的错误码
         // message - 查询失败的错误信息
       });
    }).catch(function(imError) {
      console.warn('getUserStatus error:', imError); // 获取用户状态失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    userIDList Array required

    用户 userID 列表,单次请求最多 500 个。

    Returns:
    Type
    Promise

    subscribeUserStatus(options) → {Promise}

    订阅用户状态。订阅成功后,用户状态变更 SDK 会派发 TencentCloudChat.EVENT.USER_STATUS_UPDATED 事件。

    注意1:使用该接口需要您购买旗舰版套餐,接口调用默认限制 5 秒 20 次请求。
    注意2:如果您需要订阅好友列表的状态,您只需要在控制台上打开开关即可,无需调用该接口。
    注意3:订阅列表有个数限制,超过限制后,会自动淘汰最先订阅的用户。

    Example
    let promise = chat.subscribeUserStatus({userIDList: ['user0', 'user1']});
    promise.then(function(imResponse) {
      const { failureUserList } = imResponse.data;
       // 订阅失败的用户列表
       failureUserList.forEach((item) => {
         const { userID, code, message } = item;
         // userID - 查询失败的用户 ID
         // code - 查询失败的错误码
         // message - 查询失败的错误信息
       });
    }).catch(function(imError) {
      console.warn('subscribeUserStatus error:', imError); // 订阅用户状态失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    userIDList Array required

    用户 userID 列表,单次请求最多 100 个。

    Returns:
    Type
    Promise

    unsubscribeUserStatus(options) → {Promise}

    取消订阅用户状态。取消订阅成功后,用户状态变更 SDK 不会派发 TencentCloudChat.EVENT.USER_STATUS_UPDATED 事件。

    注意1:使用该接口需要您购买旗舰版套餐,接口调用默认限制 5 秒 20 次请求。

    Examples
    // 取消当前部分用户的订阅
    let promise = chat.unsubscribeUserStatus({userIDList: ['user0', 'user1']});
    promise.then(function(imResponse) {
      const { failureUserList } = imResponse.data;
       // 取消订阅失败的用户列表
       failureUserList.forEach((item) => {
         const { userID, code, message } = item;
         // userID - 查询失败的用户 ID
         // code - 查询失败的错误码
         // message - 查询失败的错误信息
       });
    }).catch(function(imError) {
      console.warn('unsubscribeUserStatus error:', imError); // 取消订阅失败的相关信息
    });
    // 取消当前所有的订阅
    let promise = chat.unsubscribeUserStatus();
    promise.then(function(imResponse) {
      const { failureUserList } = imResponse.data;
       // 取消订阅失败的用户列表
       failureUserList.forEach((item) => {
         const { userID, code, message } = item;
         // userID - 查询失败的用户 ID
         // code - 查询失败的错误码
         // message - 查询失败的错误信息
       });
    }).catch(function(imError) {
      console.warn('unsubscribeUserStatus error:', imError); // 取消订阅失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object | undefined required

    参数选项,options 为 undefined 时,表示取消当前所有订阅。

    Properties
    Name Type Description
    userIDList Array | undefined required

    用户 userID 列表,单次请求最多 100 个。当 userIDList 为空数组或者 undefined 时,取消当前所有的订阅。

    Returns:
    Type
    Promise

    getFriendList() → {Promise}

    获取 SDK 缓存的好友列表。当好友列表有更新时,SDK 会派发事件 TencentCloudChat.EVENT.FRIEND_LIST_UPDATED

    Example
    let promise = chat.getFriendList();
    promise.then(function(imResponse) {
      const friendList = imResponse.data; // 好友列表
    }).catch(function(imError) {
      console.warn('getFriendList error:', imError); // 获取好友列表失败的相关信息
    });
    Returns:
    Type
    Promise

    addFriend(options) → {Promise}

    添加好友

    Example
    // 添加好友
    let promise = chat.addFriend({
      to: 'user1',
      source: 'AddSource_Type_Web',
      remark: '小橙子',
      groupName: '好友',
      wording: '我是 user0',
      type: TencentCloudChat.TYPES.SNS_ADD_TYPE_BOTH,
    });
    promise.then(function(imResponse) {
      // 添加好友的请求发送成功
      const { code } = imResponse.data;
      if (code === 30539) {
        // 30539 说明 user1 设置了【需要经过自己确认对方才能添加自己为好友】,此时 SDK 会触发 TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED 事件
      } else if (code === 0) {
        // 0 说明 user1 设置了【允许任何人添加自己为好友】,此时 SDK 会触发 TencentCloudChat.EVENT.FRIEND_LIST_UPDATED 事件
      }
    }).catch(function(imError) {
      console.warn('addFriend error:', imError); // 添加好友失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    to String required

    用户 ID

    source String required

    好友来源。

    • 加好友来源字段包含前缀和关键字两部分;
    • 加好友来源字段的前缀是:AddSource_Type_ ;
    • 关键字:必须是英文字母,且长度不得超过 8 字节,建议用一个英文单词或该英文单词的缩写;
    • 示例:加好友来源的关键字是 Android,则加好友来源字段是:AddSource_Type_Android
    wording String ''

    加好友附言:

    • 加好友附言的长度最长不得超过 256 个字节
    type String TencentCloudChat.TYPES.SNS_ADD_TYPE_BOTH

    加好友方式(默认双向加好友方式)

    • TencentCloudChat.TYPES.SNS_ADD_TYPE_SINGLE 单向加好友(单向好友:用户 A 的好友表中有用户 B,但 B 的好友表中却没有 A)
    • TencentCloudChat.TYPES.SNS_ADD_TYPE_BOTH 双向加好友(双向好友:用户 A 的好友表中有用户 B,B 的好友表中也有 A)
    remark String ''

    好友备注

    • 备注长度最长不得超过 96 个字节
    groupName String ''

    分组信息

    • 分组名长度不得超过 30 个字节
    Returns:
    Type
    Promise

    deleteFriend(options) → {Promise}

    删除好友,支持单向删除好友和双向删除好友

    注意1:userID 建议一次最大 100 个,因为数量过多可能会导致数据包太大被后台拒绝,后台限制数据包最大为 1M

    Example
    let promise = chat.deleteFriend({
      userIDList: ['user1','user2'],
      type: TencentCloudChat.TYPES.SNS_DELETE_TYPE_BOTH
    });
    promise.then(function(imResponse) {
      const { successUserIDList, failureUserIDList } = imResponse.data;
      // 删除成功的 userIDList
      successUserIDList.forEach((item) => {
        const { userID } = item;
      });
      // 删除失败的 userIDList
      failureUserIDList.forEach((item) => {
        const { userID, code, message } = item;
      });
      // 如果好友列表有变化,则 SDK 会触发 TencentCloudChat.EVENT.FRIEND_LIST_UPDATED 事件
    }).catch(function(imError) {
      console.warn('removeFromFriendList error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    userIDList Array.<String> required

    待删除的好友的 userID 列表,单次请求的 userID 数不得超过100

    type String TencentCloudChat.TYPES.SNS_DELETE_TYPE_BOTH

    删除模式(默认双向删除好友),详情可参见 删除好友

    • TencentCloudChat.TYPES.SNS_DELETE_TYPE_SINGLE 单向删除(只将 B 从 A 的好友表中删除,但不会将 A 从 B 的好友表中删除)
    • TencentCloudChat.TYPES.SNS_DELETE_TYPE_BOTH 双向删除(将 B 从 A 的好友表中删除,同时将 A 从 B 的好友表中删除)
    Returns:
    Type
    Promise

    checkFriend(options) → {Promise}

    校验好友关系

    Example
    let promise = chat.checkFriend({
      userIDList: ['user0','user1'],
      type: TencentCloudChat.TYPES.SNS_CHECK_TYPE_BOTH,
    });
    promise.then(function(imResponse) {
      const { successUserIDList, failureUserIDList } = imResponse.data;
      // 校验成功的 userIDList
      successUserIDList.forEach((item) => {
        const { userID, code, relation } = item; // 此时 code 始终为0
        // 单向校验好友关系时可能的结果有:
        // - relation: TencentCloudChat.TYPES.SNS_TYPE_NO_RELATION A 的好友表中没有 B,但无法确定 B 的好友表中是否有 A
        // - relation: TencentCloudChat.TYPES.SNS_TYPE_A_WITH_B A 的好友表中有 B,但无法确定 B 的好友表中是否有 A
        // 双向校验好友关系时可能的结果有:
        // - relation: TencentCloudChat.TYPES.SNS_TYPE_NO_RELATION A 的好友表中没有 B,B 的好友表中也没有 A
        // - relation: TencentCloudChat.TYPES.SNS_TYPE_A_WITH_B A 的好友表中有 B,但 B 的好友表中没有 A
        // - relation: TencentCloudChat.TYPES.SNS_TYPE_B_WITH_A A 的好友表中没有 B,但 B 的好友表中有 A
        // - relation: TencentCloudChat.TYPES.SNS_TYPE_BOTH_WAY A 的好友表中有 B,B 的好友表中也有 A
      });
      // 校验失败的 userIDList
      failureUserIDList.forEach((item) => {
        const { userID, code, message } = item;
      });
    }).catch(function(imError) {
      console.warn('checkFriend error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    userIDList Array.<String> required

    要校验的 userID 列表,单次请求的 userID 数不得超过1000

    type String TencentCloudChat.TYPES.SNS_CHECK_TYPE_BOTH

    校验模式(默认双向校验好友关系),详情可参见 校验好友

    • TencentCloudChat.TYPES.SNS_CHECK_TYPE_SINGLE 单向校验好友关系(只会检查 A 的好友表中是否有 B,不会检查 B 的好友表中是否有 A)
    • TencentCloudChat.TYPES.SNS_CHECK_TYPE_BOTH 双向校验好友关系(既会检查 A 的好友表中是否有 B,也会检查 B 的好友表中是否有 A)
    Returns:
    Type
    Promise

    getFriendProfile(options) → {Promise}

    获取指定好友的全量好友数据(包含好友标配字段和好友自定义字段)和全量资料数据(包含资料标配字段和资料自定义字段)。

    Example
    // 获取好友标配字段、好友自定义字段、资料标配字段、资料自定义字段
    let promise = chat.getFriendProfile({
      userIDList: ['user0','user1']
    });
    promise.then(function(imResponse) {
      const { friendList, failureUserIDList } = imResponse.data;
      friendList.forEach((friend) => {
        // Friend 对象
      });
      // 失败的 userIDList
      failureUserIDList.forEach((item) => {
        const { userID, code, message } = item;
      });
    }).catch(function(imError) {
      console.warn('getFriendProfile error:', imError); // 获取失败
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    userIDList Array.<String> required

    好友的 userID 列表

    Returns:
    Type
    Promise

    updateFriend(options) → {Promise}

    更新好友的关系链数据,只支持好友备注、关系链自定义字段的更新操作。

    注意1:更新好友分组,请使用 addToFriendGroupremoveFromFriendGroup 接口

    Examples
    // 更新好友备注
    let promise = chat.updateFriend({
      userID: 'user1',
      remark: 'helloworld'
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data); // Friend 实例
    }).catch(function(imError) {
      console.warn('getFriendProfile error:', imError); // 更新失败
    });
    // 更新好友自定义字段
    let promise = chat.updateFriend({
      userID: 'user1',
      friendCustomField: [
        // 好友自定义字段必须以 Tag_SNS_Custom 为前缀
        { key: 'Tag_SNS_Custom_test1', value: 'hello' },
        { key: 'Tag_SNS_Custom_test2', value: 'world' },
      ]
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data); // Friend 实例
    }).catch(function(imError) {
      console.warn('getFriendProfile error:', imError); // 更新失败
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    userID String required

    要更新的好友 userID

    remark String ''

    好友备注

    • 备注长度最长不得超过 96 个字节
    friendCustomField Array.<Object>

    好友自定义字段键值对集合,可根据业务侧需要使用,详细请参考: https://cloud.tencent.com/document/product/269/1501#.E8.87.AA.E5.AE.9A.E4.B9.89.E5.A5.BD.E5.8F.8B.E5.AD.97.E6.AE.B5

    Returns:
    Type
    Promise

    getFriendApplicationList() → {Promise}

    获取 SDK 缓存的好友申请列表。当好友申请列表有更新时,SDK 会派发事件 TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED

    注意1:如果您的个人资料(通过 getMyProfile 接口获取)中 allowType 设置为 TencentCloudChat.TYPES.ALLOW_TYPE_ALLOW_ANY(当被人加好友时:允许任何人添加自己为好友),此接口将无法拉取到好友申请列表。

    Example
    let promise = chat.getFriendApplicationList();
    promise.then(function(imResponse) {
      // friendApplicationList - 好友申请列表 - [FriendApplication]
      // FriendApplication 数据结构详情请参考 https://web.sdk.qcloud.com/im/doc/v3/zh-cn/FriendApplication.html
      // unreadCount - 好友申请的未读数
      // const { friendApplicationList, unreadCount } = imResponse.data;
    });
    Returns:
    Type
    Promise

    acceptFriendApplication(options) → {Promise}

    同意好友申请

    Example
    let promise = chat.acceptFriendApplication({
      userID: 'user1',
      remark: '客服小亮',
      type: TencentCloudChat.TYPES.SNS_APPLICATION_AGREE_AND_ADD
    });
    promise.then(function(imResponse) {
      // 同意好友成功后,SDK 会触发 TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED 事件
    }).catch(function(imError) {
      console.warn('acceptFriendApplication error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    userID String required

    待同意的好友申请的 userID

    remark String ''

    给好友设置的备注

    type String required

    同意方式

    • TencentCloudChat.TYPES.SNS_APPLICATION_AGREE 同意添加单向好友
    • TencentCloudChat.TYPES.SNS_APPLICATION_AGREE_AND_ADD 同意并添加为双向好友
    Returns:
    Type
    Promise

    refuseFriendApplication(options) → {Promise}

    拒绝好友申请

    Example
    let promise = chat.refuseFriendApplication({
      userID: 'user1',
    });
    promise.then(function(imResponse) {
    // 拒绝成功后,SDK 会触发 TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED 事件
    }).catch(function(imError) {
      console.warn('refuseFriendApplication error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    userID String required

    拒绝的好友申请的 userID

    Returns:
    Type
    Promise

    deleteFriendApplication(options) → {Promise}

    删除好友申请

    Example
    let promise = chat.deleteFriendApplication({
      userID: 'user1',
      type: TencentCloudChat.TYPES.SNS_APPLICATION_SENT_TO_ME
    });
    promise.then(function(imResponse) {
      // 删除成功后,SDK 会触发 TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED 事件
    }).catch(function(imError) {
      console.warn('deleteFriendApplication error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    userID String required

    待删除的好友申请的 userID

    type String required

    好友申请的类型

    • TencentCloudChat.TYPES.SNS_APPLICATION_SENT_TO_ME 别人发给我的好友申请
    • TencentCloudChat.TYPES.SNS_APPLICATION_SENT_BY_ME 我发给别人的好友申请
    Returns:
    Type
    Promise

    setFriendApplicationRead() → {Promise}

    上报好友申请已读

    Example
    // 上报好友申请已读
    let promise = chat.setFriendApplicationRead();
    promise.then(function(imResponse) {
      // 已读上报成功
    }).catch(function(imError) {
      console.warn('setFriendApplicationRead error:', imError);
    });
    Returns:
    Type
    Promise

    getFriendGroupList() → {Promise}

    获取 SDK 缓存的好友分组列表。当好友分组列表有更新时,SDK 会派发事件 TencentCloudChat.EVENT.FRIEND_GROUP_LIST_UPDATED

    Example
    let promise = chat.getFriendGroupList();
    promise.then(function(imResponse) {
      const friendGroupList = imResponse.data; // 好友分组列表
    }).catch(function(imError) {
      console.warn('getFriendGroupList error:', imError); // 获取好友分组列表失败的相关信息
    });
    Returns:
    Type
    Promise

    createFriendGroup(options) → {Promise}

    创建好友分组

    Example
    let promise = chat.createFriendGroup({
      name: '我的好友分组1',
      userIDList: ['user0','user1']
    });
    promise.then(function(imResponse) {
      const { friendGroup,failureUserIDList } = imResponse;
      // friendGroup - 好友分组实例
      // failureUserIDList - 失败的 userID 列表
      // 创建成功后,SDK 会触发 TencentCloudChat.EVENT.FRIEND_GROUP_LIST_UPDATED 事件
    }).catch(function(imError) {
      console.warn('getFriendGroupInfo error:', imError); // 获取失败
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    name String required

    分组名称

    userIDList Array.<String> required

    要添加到分组的好友 userID 列表

    Returns:
    Type
    Promise

    deleteFriendGroup(options) → {Promise}

    删除好友分组

    Example
    let promise = chat.deleteFriendGroup({
      name: '我的好友分组1',
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 被删除的分组实例
      // 删除成功后,SDK 会触发 TencentCloudChat.EVENT.FRIEND_GROUP_LIST_UPDATED 事件
    }).catch(function(imError) {
      console.warn('deleteFriendGroup error:', imError); // 获取失败
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    name String required

    要删除的分组名称

    Returns:
    Type
    Promise

    addToFriendGroup(options) → {Promise}

    添加好友到分组列表

    Example
    let promise = chat.addToFriendGroup({
      name: '我的好友分组1',
      userIDList: ['user1','user2'],
    });
    promise.then(function(imResponse) {
      const { friendGroup, failureUserIDList } = imResponse.data;
      // friendGroup - 好友分组实例
      // failureUserIDList - 失败的 userID 列表
      // 添加成功后,SDK 会触发 TencentCloudChat.EVENT.FRIEND_GROUP_LIST_UPDATED 事件
    }).catch(function(imError) {
      console.warn('addToFriendGroup error:', imError); // 获取失败
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    name String required

    分组名称

    userIDList Array.<String> required

    要添加的好友 userID 列表

    Returns:
    Type
    Promise

    removeFromFriendGroup(options) → {Promise}

    从好友分组移除好友

    Example
    let promise = chat.removeFromFriendGroup({
      name: '我的好友分组1',
      userIDList: ['user1','user2'],
    });
    promise.then(function(imResponse) {
      const { friendGroup, failureUserIDList } = imResponse.data;
      // friendGroup - 好友分组实例
      // failureUserIDList - 失败的 userID 列表
      // 移除成功后,SDK 会触发 TencentCloudChat.EVENT.FRIEND_GROUP_LIST_UPDATED 事件
    }).catch(function(imError) {
      console.warn('addToFriendGroup error:', imError); // 获取失败
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    name String required

    分组名称

    userIDList Array.<String> required

    要移除的好友 userID 列表

    Returns:
    Type
    Promise

    renameFriendGroup(options) → {Promise}

    修改好友分组的名称

    Example
    let promise = chat.renameFriendGroup({
      oldName: '好友',
      newName: '闺蜜'
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data); // FriendGroup 实例
      // 修改成功后,SDK 会触发 TencentCloudChat.EVENT.FRIEND_GROUP_LIST_UPDATED 事件
    }).catch(function(imError) {
      console.warn('updateMyProfile error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    oldName String required

    旧的分组名称

    newName String required

    新的分组名称

    Returns:
    Type
    Promise

    followUser(userIDList) → {Promise}

    关注用户

    注意1:v3.2.6 起支持,使用该接口需要您购买旗舰版套餐。
    注意2:该接口一次最多支持关注 20 个用户(除了自己之外,其他用户都可以关注)。
    注意3:每个用户的关注用户数量上限为 5000 人,粉丝用户数量无上限。

    Example
    let promise = chat.followUser(['user1', 'user2']);
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 关注的结果信息
    }).catch(function(imError) {
      console.warn('followUser error:', imError);
    });
    Parameters:
    Name Type Description
    userIDList Array.<String> required

    用户 userID 列表,一次最多支持关注 20 个用户。

    Returns:
    Type
    Promise

    unfollowUser(userIDList) → {Promise}

    取消关注用户

    注意1:v3.2.6 起支持,使用该接口需要您购买旗舰版套餐。
    注意2:一次最多支持取消关注 20 个用户。

    Example
    let promise = chat.unfollowUser(['user1', 'user2']);
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 取消关注的结果信息
    }).catch(function(imError) {
      console.warn('unfollowUser error:', imError);
    });
    Parameters:
    Name Type Description
    userIDList Array.<String> required

    用户 userID 列表,一次最多支持取消关注 20 个用户。

    Returns:
    Type
    Promise

    getMyFollowersList(nextCursoropt) → {Promise}

    获取我的粉丝列表

    注意1:v3.2.6 起支持,使用该接口需要您购买旗舰版套餐。
    注意2:该接口每次最多返回 500 个用户。

    Example
    let promise = chat.getMyFollowersList();
    promise.then(function(imResponse) {
      const { resultList, nextCursor = '' } = imResponse.data;
      // ressultList - 我的粉丝列表
      // nextCursor - 分页续拉的标识
      if (nextCursor != '') {
        // 需要续拉
      }
    }).catch(function(imError) {
      console.warn('getMyFollowersList error:', imError);
    });
    Parameters:
    Name Type Default Description
    nextCursor String ''

    分页拉取起始位置,首页拉取默认为空,可不传,获取成功时 nextCursor 不为 '',需要分页,可以传入该值再次拉取,直至 nextCursor 返回为 ''。

    Returns:
    Type
    Promise

    getMyFollowingList(nextCursoropt) → {Promise}

    获取我的关注列表

    注意1:v3.2.6 起支持,使用该接口需要您购买旗舰版套餐。
    注意2:该接口每次最多返回 500 个用户。

    Example
    let promise = chat.getMyFollowingList();
    promise.then(function(imResponse) {
      const { resultList, nextCursor = '' } = imResponse.data;
      // ressultList - 我的关注列表
      // nextCursor - 分页续拉的标识
      if (nextCursor != '') {
        // 需要续拉
      }
    }).catch(function(imError) {
      console.warn('getMyFollowingList error:', imError);
    });
    Parameters:
    Name Type Default Description
    nextCursor String ''

    分页拉取起始位置,首页拉取默认为空,可不传,获取成功时 nextCursor 不为 '',需要分页,可以传入该值再次拉取,直至 nextCursor 返回为 ''。

    Returns:
    Type
    Promise

    getMutualFollowersList(nextCursoropt) → {Promise}

    获取互关列表

    注意1:v3.2.6 起支持,使用该接口需要您购买旗舰版套餐。
    注意2:该接口每次最多返回 500 个用户。

    Example
    let promise = chat.getMutualFollowersList();
    promise.then(function(imResponse) {
      const { resultList, nextCursor = '' } = imResponse.data;
      // ressultList - 互关列表
      // nextCursor - 分页续拉的标识
      if (nextCursor != '') {
        // 需要续拉
      }
    }).catch(function(imError) {
      console.warn('getMutualFollowersList error:', imError);
    });
    Parameters:
    Name Type Default Description
    nextCursor String ''

    分页拉取起始位置,首页拉取默认为空,可不传,获取成功时 nextCursor 不为 '',需要分页,可以传入该值再次拉取,直至 nextCursor 返回为 ''。

    Returns:
    Type
    Promise

    getUserFollowInfo(userIDList) → {Promise}

    获取指定用户的 关注/粉丝/互关 数量信息

    注意1:v3.2.6 起支持,使用该接口需要您购买旗舰版套餐。

    Examples
    // 获取自己的 关注/粉丝/互关 数量信息
    let promise = chat.getUserFollowInfo();
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 获取成功
    }).catch(function(imError) {
      console.warn('getUserFollowInfo error:', imError);
    });
    // 获取指定用户的 关注/粉丝/互关 数量信息
    let promise = chat.getUserFollowInfo(['user1', 'user2']);
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 获取成功
    }).catch(function(imError) {
      console.warn('getUserFollowInfo error:', imError);
    });
    Parameters:
    Name Type Description
    userIDList Array.<String> required

    用户 userID 列表,不传 userIDList 表示获取自己的 关注/粉丝/互关 数量信息

    Returns:
    Type
    Promise

    checkFollowType(userIDList) → {Promise}

    检查指定用户的关注关系

    注意1:v3.2.6 起支持,使用该接口需要您购买旗舰版套餐。
    注意2:业务侧调用该接口默认限制 5 秒 20 次请求,超频后 SDK 返回错误码 2996。

    Example
    let promise = chat.checkFollowType(['user1', 'user2']);
    promise.then(function(imResponse) {
      console.log(imResponse.data); // 校验结果列表
      imResponse.data.forEach((item) => {
        // item.userID - 用户 userID
        // item.followType - 关注关系(0 - 没有关系, 1 - 粉丝, 2 - 关注, 3 - 互关)
      });
    }).catch(function(imError) {
      console.warn('checkFollowType error:', imError);
    });
    Parameters:
    Name Type Description
    userIDList Array.<String> required

    待校验用户 userID 列表,单次请求最多支持 100 个 userID。

    Returns:
    Type
    Promise

    getGroupList() → {Promise}

    需要渲染或刷新【我的群组列表】时,调用该接口获取群组列表,更多详情请参见 Group

    注意1:该接口返回 SDK 从云端已同步的群组列表,不包含 TencentCloudChat.TYPES.GRP_AVCHATROOM(直播群)类型的群组和支持话题的社群。
    注意2:接口返回的群组列表,只包含群的基础资料(群类型、群名称、群头像、@信息列表)。
    注意3:如果想要获取群的详细资料,请使用 getGroupProfile

    See:
    Example
    // 该接口默认只会拉取这些资料:群类型、群名称、群头像、最后一条消息的时间。
    let promise = chat.getGroupList();
    promise.then(function(imResponse) {
      console.log(imResponse.data.groupList); // 群组列表
    }).catch(function(imError) {
      console.warn('getGroupList error:', imError); // 获取群组列表失败的相关信息
    });
    Returns:
    Type
    Promise

    getGroupProfile(options) → {Promise}

    获取群详细资料

    See:
    Example
    let promise = chat.getGroupProfile({ groupID: 'group1', groupCustomFieldFilter: ['key1','key2'] });
    promise.then(function(imResponse) {
      console.log(imResponse.data.group);
    }).catch(function(imError) {
      console.warn('getGroupProfile error:', imError); // 获取群详细资料失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群组ID

    groupCustomFieldFilter Array.<String>

    群组维度的自定义字段过滤器,指定需要获取的群组维度的自定义字段,详情请参阅 自定义字段

    Returns:
    Type
    Promise

    createGroup(options) → {Promise}

    创建群组

    注意1:该接口创建 TencentCloudChat.TYPES.GRP_AVCHATROOM(直播群) 后,需调用 joinGroup 接口加入群组后,才能进行消息收发流程。
    注意2:该接口可以创建支持话题的社群。
    注意3:创建群组时可以设置 inviteOption 选项控制邀请进群处理方式(直播群不支持 inviteOption)。
    注意4:创建群组时自定义群组 ID。自定义群组 ID 必须为可打印 ASCII 字符(0x20-0x7e),最长48个字节,且前缀不能为 @TGS#(避免与默认分配的群组 ID 混淆)。

    See:
    Examples
    // 创建好友工作群
    let promise = chat.createGroup({
      type: TencentCloudChat.TYPES.GRP_WORK,
      name: 'WebSDK',
      memberList: [{
        userID: 'user1',
        // 群成员维度的自定义字段,默认情况是没有的,需要开通,详情请参阅自定义字段
        memberCustomField: [{key: 'group_member_test', value: 'test'}]
      }, {
        userID: 'user2'
      }] // 如果填写了 memberList,则必须填写 userID
    });
    promise.then(function(imResponse) { // 创建成功
      console.log(imResponse.data.group); // 创建的群的资料
      // 创建群时指定了成员列表,但是成员中存在超过了“单个用户可加入群组数”限制的情况
      // 一个用户 userX 最多允许加入 N 个群,如果已经加入了 N 个群,此时创建群再指定 userX 为群成员,则 userX 不能正常加群
      // SDK 将 userX 的信息放入 overLimitUserIDList,供接入侧处理
      console.log(imResponse.data.overLimitUserIDList); // 超过了“单个用户可加入群组数”限制的用户列表
    }).catch(function(imError) {
      console.warn('createGroup error:', imError); // 创建群组失败的相关信息
    });
    // 创建支持话题的社群
    let promise = chat.createGroup({
      type: TencentCloudChat.TYPES.GRP_COMMUNITY,
      name: 'WebSDK',
      isSupportTopic: true,
    });
    promise.then(function(imResponse) { // 创建成功
      console.log(imResponse.data.group); // 创建的群的资料
    }).catch(function(imError) {
      console.warn('createGroup error:', imError); // 创建群组失败的相关信息
    });
    // 创建邀请进群需要审批的 TencentCloudChat.TYPES.GRP_PUBLIC 类型群组
    let promise = chat.createGroup({
      type: TencentCloudChat.TYPES.GRP_PUBLIC,
      name: 'WebSDK',
      inviteOption: TencentCloudChat.TYPES.INVITE_OPTIONS_NEED_PERMISSION,
    });
    promise.then(function(imResponse) { // 创建成功
      console.log(imResponse.data.group); // 创建的群的资料
    }).catch(function(imError) {
      console.warn('createGroup error:', imError); // 创建群组失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数集

    Properties
    Name Type Default Description
    name String required

    必填,群组名称,最长100字节,使用 UTF-8 编码,1个汉字占3个字节,不可调整

    type String TencentCloudChat.TYPES.GRP_WORK

    群组类型,包括:

    • TencentCloudChat.TYPES.GRP_WORK(好友工作群,默认)
    • TencentCloudChat.TYPES.GRP_PUBLIC(陌生人社交群)
    • TencentCloudChat.TYPES.GRP_MEETING(临时会议群)
    • TencentCloudChat.TYPES.GRP_AVCHATROOM(直播群)
    • TencentCloudChat.TYPES.GRP_COMMUNITY(社群)
    groupID String

    群组ID。不填该字段时,会自动为群组创建一个唯一的群 ID

    introduction String

    群简介,最长400字节,使用 UTF-8 编码,1个汉字占3个字节,不可调整

    notification String

    群公告,最长400字节,使用 UTF-8 编码,1个汉字占3个字节,不可调整

    avatar String

    群头像 URL,最长500字节

    maxMemberNum Number

    最大群成员数量,缺省时的默认值:好友工作群是200,陌生人社交群是2000,临时会议群是10000,直播群无限制

    joinOption String TencentCloudChat.TYPES.JOIN_OPTIONS_FREE_ACCESS

    申请加群处理方式。

    • TencentCloudChat.TYPES.JOIN_OPTIONS_FREE_ACCESS (自由加入)
    • TencentCloudChat.TYPES.JOIN_OPTIONS_NEED_PERMISSION (需要验证)
    • TencentCloudChat.TYPES.JOIN_OPTIONS_DISABLE_APPLY (禁止加群)
      注意:创建 TencentCloudChat.TYPES.GRP_WORK, TencentCloudChat.TYPES.GRP_MEETING, TencentCloudChat.TYPES.GRP_AVCHATROOM 类型的群组不能填写该字段。好友工作群禁止申请加群,临时会议群和直播群自由加入。
    inviteOption String TencentCloudChat.TYPES.INVITE_OPTIONS_DISABLE_INVITE

    邀请进群处理方式。

    • TencentCloudChat.TYPES.INVITE_OPTIONS_FREE_ACCESS (无需审批直接邀请进群)
    • TencentCloudChat.TYPES.INVITE_OPTIONS_NEED_PERMISSION (需要群主/群管理员验证)
    • TencentCloudChat.TYPES.INVITE_OPTIONS_DISABLE_INVITE (禁止邀请)
      注意:TencentCloudChat.TYPES.GRP_AVCHATROOM 类型的群组该属性不支持设置,其他类型群组均支持。
    memberList Array.<Object>

    初始群成员列表,最多 100 个。创建直播群时不能添加成员

    Properties
    Name Type Description
    userID String required

    必填,群成员的 userID

    role String

    成员身份,可选值只有Admin,表示添加该成员并设其为管理员

    memberCustomField Array.<Object>

    群成员维度的自定义字段,默认情况是没有的,需要开通,详情请参阅自定义字段

    groupCustomField Array.<Object>

    群组维度的自定义字段,默认情况是没有的,需要开通,详情请参阅群成员资料

    isSupportTopic Boolean required

    创建支持话题的社群时必填, true - 创建支持话题的社群 false - 创建普通社群。

    Returns:
    Type
    Promise

    dismissGroup(groupID) → {Promise}

    群主可调用该接口解散群组。

    注意1:群主不能解散好友工作群。
    注意2:群解散后,若登录态未失效,SDK 仍会保留对应的群会话,如果您想删除会话,请使用 deleteConversation

    See:
    Example
    let promise = chat.dismissGroup('group1');
    promise.then(function(imResponse) { // 解散成功
      console.log(imResponse.data.groupID); // 被解散的群组 ID
    }).catch(function(imError) {
      console.warn('dismissGroup error:', imError); // 解散群组失败的相关信息
    });
    Parameters:
    Name Type Description
    groupID String required

    群组 ID

    Returns:
    Type
    Promise

    updateGroupProfile(options) → {Promise}

    修改群组资料。

    注意1:此接口不支持修改最大群成员数量,如需修改请使用 REST API
    注意2:该接口可以修改群组的邀请选项。
    注意3:群资料变更通知,不同类型的群通知方式不一样,详情请参见 群组-消息差异
    注意4:直播群不支持设置 inviteOption。

    See:
    Examples
    let promise = chat.updateGroupProfile({
      groupID: 'group1',
      name: 'new name', // 修改群名称
      introduction: 'this is introduction.', // 修改群简介
      // 群成员能收到群自定义字段变更的群提示消息,且能获取到相关的内容,详见 Message.payload.newGroupProfile.groupCustomField
      groupCustomField: [{ key: 'group_level', value: 'high'}] // 修改群组维度自定义字段
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data.group) // 修改成功后的群组详细资料
    }).catch(function(imError) {
      console.warn('updateGroupProfile error:', imError); // 修改群组资料失败的相关信息
    });
    let promise = chat.updateGroupProfile({
      groupID: 'group1',
      muteAllMembers: true, // true 表示全体禁言,false表示取消全体禁言
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data.group) // 修改成功后的群组详细资料
    }).catch(function(imError) {
      console.warn('updateGroupProfile error:', imError); // 修改群组资料失败的相关信息
    });
    // 修改邀请进群选项
    let promise = chat.updateGroupProfile({
      groupID: 'group1',
      inviteOption: TencentCloudChat.TYPES.INVITE_OPTIONS_NEED_PERMISSION,
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data.group) // 修改成功后的群组详细资料
    }).catch(function(imError) {
      console.warn('updateGroupProfile error:', imError); // 修改群组资料失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    请求参数

    Properties
    Name Type Default Description
    groupID String required

    群ID

    name String

    群名称,最长100字节,使用 UTF-8 编码,1个汉字占3个字节,不可调整

    avatar String

    群头像URL,最长500字节

    introduction String

    群简介,最长400字节,使用 UTF-8 编码,1个汉字占3个字节,不可调整

    notification String

    群公告,最长400字节,使用 UTF-8 编码,1个汉字占3个字节,不可调整

    muteAllMembers Boolean required

    设置全体禁言,true 表示全体禁言,false 表示取消全体禁言

    joinOption String TencentCloudChat.TYPES.JOIN_OPTIONS_FREE_ACCESS

    申请加群处理方式。

    • TencentCloudChat.TYPES.JOIN_OPTIONS_FREE_ACCESS (自由加入)
    • TencentCloudChat.TYPES.JOIN_OPTIONS_NEED_PERMISSION (需要验证)
    • TencentCloudChat.TYPES.JOIN_OPTIONS_DISABLE_APPLY (禁止加群)
      注意:TencentCloudChat.TYPES.GRP_WORK, TencentCloudChat.TYPES.GRP_MEETING, TencentCloudChat.TYPES.GRP_AVCHATROOM 类型群组的该属性不允许修改。好友工作群禁止申请加群,临时会议群和直播群自由加入。
    inviteOption String TencentCloudChat.TYPES.INVITE_OPTIONS_DISABLE_INVITE

    邀请进群处理方式。

    • TencentCloudChat.TYPES.INVITE_OPTIONS_FREE_ACCESS (无需审批直接邀请进群)
    • TencentCloudChat.TYPES.INVITE_OPTIONS_NEED_PERMISSION (需要群主/群管理员验证)
    • TencentCloudChat.TYPES.INVITE_OPTIONS_DISABLE_INVITE (禁止邀请)
      注意:TencentCloudChat.TYPES.GRP_AVCHATROOM 类型群组的该属性不允许修改,其他类型群组均支持修改。
    groupCustomField Array.<Object>

    群自定义字段。默认情况是没有的。开通群组维度的自定义字段详情请参见 自定义字段

    Properties
    Name Type Description
    key String required

    自定义字段的 Key

    value String required

    自定义字段的 Value

    Returns:
    Type
    Promise

    joinGroup(options) → {Promise}

    申请加群的接口,申请加入某个群组时调用。

    注意1:好友工作群不允许申请加群,只能通过 addGroupMember 方式添加。
    注意2:同一用户同时只能加入一个直播群。【例如】用户已在直播群 A 中,再加入直播群 B,SDK 会先退出直播群 A,然后加入直播群 B。
    注意3:获取直播群在线成员列表,需要您购买旗舰版套餐,请参考 getGroupMemberList

    See:
    Example
    let promise = chat.joinGroup({ groupID: 'group1' });
    promise.then(function(imResponse) {
      switch (imResponse.data.status) {
        case TencentCloudChat.TYPES.JOIN_STATUS_WAIT_APPROVAL: // 等待管理员同意
          break;
        case TencentCloudChat.TYPES.JOIN_STATUS_SUCCESS: // 加群成功
          console.log(imResponse.data.group); // 加入的群组资料
          break;
        case TencentCloudChat.TYPES.JOIN_STATUS_ALREADY_IN_GROUP: // 已经在群中
          break;
        default:
          break;
      }
    }).catch(function(imError){
      console.warn('joinGroup error:', imError); // 申请加群失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群 ID

    applyMessage String required

    附言

    Returns:
    Type
    Promise

    quitGroup(groupID) → {Promise}

    退出群组。

    注意1:群主只能退出好友工作群,退出后该好友工作群无群主。
    注意2:退出群组后,若登录态未失效,SDK 仍会保留对应的群会话,如果您想删除会话,请使用 deleteConversation

    See:
    Example
    let promise = chat.quitGroup('group1');
    promise.then(function(imResponse) {
      console.log(imResponse.data.groupID); // 退出成功的群 ID
    }).catch(function(imError){
      console.warn('quitGroup error:', imError); // 退出群组失败的相关信息
    });
    Parameters:
    Name Type Description
    groupID String required

    群组 ID

    Returns:

    成功时 then 回调参数中包含退出的群组 ID

    Type
    Promise

    searchGroupByID(groupID) → {Promise}

    通过 groupID 搜索群组。

    注意:TencentCloudChat.TYPES.GRP_WORK 类型的群组(好友工作群)不能被搜索。

    See:
    Example
    let promise = chat.searchGroupByID('group1');
    promise.then(function(imResponse) {
      const group = imResponse.data.group; // 群组信息
    }).catch(function(imError) {
      console.warn('searchGroupByID error:', imError); // 搜素群组失败的相关信息
    });
    Parameters:
    Name Type Description
    groupID String required

    群组 ID

    Returns:
    Type
    Promise

    getGroupOnlineMemberCount(groupID) → {Promise}

    获取群在线人数。

    注意1:v3.2.0起,此接口可获取所有类型的群的在线人数。
    注意2:调用此接口查询直播群人数的的频率建议控制在5~10秒一次;查询其它类型的群的在线人数限频60秒一次。

    See:
    Example
    let promise = chat.getGroupOnlineMemberCount('group1');
    promise.then(function(imResponse) {
      console.log(imResponse.data.memberCount);
    }).catch(function(imError) {
      console.warn('getGroupOnlineMemberCount error:', imError); // 获取群在线人数失败的相关信息
    });
    Parameters:
    Name Type Description
    groupID String required

    群组ID

    Returns:
    Type
    Promise

    changeGroupOwner(options) → {Promise}

    转让群组。只有群主有权限操作。

    注意:只有群主拥有转让的权限。TencentCloudChat.TYPES.GRP_AVCHATROOM(直播群)类型的群组不能转让。

    See:
    Example
    let promise = chat.changeGroupOwner({
      groupID: 'group1',
      newOwnerID: 'user2'
    });
    promise.then(function(imResponse) { // 转让成功
      console.log(imResponse.data.group); // 群组资料
    }).catch(function(imError) { // 转让失败
      console.warn('changeGroupOwner error:', imError); // 转让群组失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    待转让的群组 ID

    newOwnerID String required

    新群主的 ID

    Returns:
    Type
    Promise

    getGroupApplicationList() → {Promise}

    获取加群申请和邀请进群申请列表。

    注意:v3.1.2起,获取加群申请列表支持返回附言信息

    Example
    let promise = chat.getGroupApplicationList();
    promise.then(function(imResponse) {
      const { applicationList } = imResponse.data;
      applicationList.forEach((item) => {
        // item.applicant - 申请者 userID
        // item.applicantNick - 申请者昵称
        // item.groupID - 群 ID
        // item.groupName - 群名称
        // item.applicationType - 申请类型:0 加群申请,2 邀请进群申请
        // item.userID - applicationType = 2时,是被邀请用户的 userID
        // item.note - 附言信息,邀请加群暂不支持,返回为空字符串
        // 接入侧可调用 handleGroupApplication 接口同意或拒绝加群申请
        chat.handleGroupApplication({
          handleAction: 'Agree',
          application: {...item},
        });
      });
    }).catch(function(imError) {
      console.warn('getGroupApplicationList error:', imError);
    });
    Returns:
    Type
    Promise

    handleGroupApplication(options) → {Promise}

    处理申请加群和邀请进群(同意或拒绝)

    注意1:如果一个群有多位群管理员,当有人申请加群时,所有在线的群管理员都会收到申请加群的群系统通知。如果某位群管理员处理了这个申请(同意或者拒绝),则其他管理员无法重复处理(即不能修改处理的结果)。
    注意2:支持处理邀请进群审批,且只能通过获取未决列表成功后的信息进行处理。
    注意3:如果一个群有多群位管理员,当有人邀请用户进群时,所有在线的群管理员都会收到邀请进群的群系统通知。如果某位群管理员通过未决列表处理了这个申请(同意或者拒绝),则其他管理员无法重复处理(即不能修改处理的结果)。

    See:
    Examples
    // 通过系统通知处理加群申请
    let promise = chat.handleGroupApplication({
      handleAction: 'Agree',
      handleMessage: '欢迎欢迎',
      message: message // 申请加群群系统通知的消息实例
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data.group); // 群组资料
    }).catch(function(imError){
      console.warn('handleGroupApplication error:', imError); // 错误信息
    });
    // 通过获取未决列表处理加群申请
    let promise = chat.getGroupApplicationList();
    promise.then(function(imResponse) {
      const { applicationList } = imResponse.data;
      applicationList.forEach((item) => {
        if (item.applicationType === 0) {
          chat.handleGroupApplication({
            handleAction: 'Agree',
            application: {...item},
          });
        }
      });
    }).catch(function(imError) {
      console.warn('getGroupApplicationList error:', imError);
    });
    // 通过获取未决列表处理邀请进群申请
    let promise = chat.getGroupApplicationList();
    promise.then(function(imResponse) {
      const { applicationList } = imResponse.data;
      applicationList.forEach((item) => {
        if (item.applicationType === 2) {
          chat.handleGroupApplication({
            handleAction: 'Agree',
            application: {...item},
          });
        }
      });
    }).catch(function(imError) {
      console.warn('getGroupApplicationList error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    handleAction String required

    处理结果 Agree(同意) / Reject(拒绝)

    handleMessage String

    附言

    message Message

    对应【群系统通知】的消息实例

    application Object

    加群申请

    Returns:
    Type
    Promise

    initGroupAttributes(options) → {Promise}

    初始化群属性。业务侧需要根据应用场景控制该接口的操作权限。初始化成功后,群组成员都会收到 GROUP_ATTRIBUTES_UPDATED 事件。

    注意1:话题不支持群属性。
    注意2:直播群(AVChatRoom)使用该接口前必须先调用 joinGroup 加群,Public、Meeting、Work、Community 类型群组如果已加群,则不需要再调用 joinGroup
    注意3:接口返回 10056 错误码时,请调用 getGroupAttributes 获取到服务端最新的群属性数据后再进行初始化操作。
    注意4:群属性 key 最多支持 16 个,大小限制为 32 字节;value 大小限制为 4k;总的 groupAttributes(包括 key 和 value)大小限制为 16k。

    Example
    let promise = chat.initGroupAttributes({
      groupID: 'group1',
      groupAttributes: { key1: 'value1', key2: 'value2' }
    });
    promise.then(function(imResponse) { // 初始化成功
      console.log(imResponse.data.groupAttributes); // 初始化成功的群属性
    }).catch(function(imError) { // 初始化失败
      console.warn('initGroupAttributes error:', imError); // 初始化群属性失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群组ID

    groupAttributes Object required

    群属性

    Returns:
    Type
    Promise

    setGroupAttributes(options) → {Promise}

    设置群属性。设置成功后,群组成员都会收到 GROUP_ATTRIBUTES_UPDATED 事件。

    注意1:话题不支持群属性。
    注意2:直播群(AVChatRoom)使用该接口前必须先调用 joinGroup 加群,Public、Meeting、Work、Community 类型群组如果已加群,则不需要再调用 joinGroup
    注意3:接口返回 10056 错误码时,请调用 getGroupAttributes 获取到服务端最新的群属性数据后再进行修改操作。

    Example
    let promise = chat.setGroupAttributes({
      groupID: 'group1',
      groupAttributes: { key1: 'value1', key2: 'value2' }
    });
    promise.then(function(imResponse) { // 设置成功
      console.log(imResponse.data.groupAttributes); // 设置成功的群属性
    }).catch(function(imError) { // 设置失败
      console.warn('setGroupAttributes error:', imError); // 设置群属性失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群组ID

    groupAttributes Object required

    群属性

    Returns:
    Type
    Promise

    deleteGroupAttributes(options) → {Promise}

    删除群属性。删除成功后,群组成员都会收到 GROUP_ATTRIBUTES_UPDATED 事件。

    注意1:话题不支持群属性。
    注意2:直播群(AVChatRoom)使用该接口前必须先调用 joinGroup 加群,Public、Meeting、Work、Community 类型群组如果已加群,则不需要再调用 joinGroup
    注意3:接口返回 10056 错误码时,请调用 getGroupAttributes 获取到服务端最新的群属性数据后再进行删除操作。
    注意4:keyList 传入非空数组表示删除指定的群属性 key-value,传入空数组表示删除全部群属性。

    Examples
    // 删除指定的群属性 key-value
    let promise = chat.deleteGroupAttributes({
      groupID: 'group1',
      keyList: ['key1', 'key2']
    });
    promise.then(function(imResponse) { // 删除成功
      console.log(imResponse.data.keyList); // 删除成功的群属性 key 列表
    }).catch(function(imError) { // 删除失败
      console.warn('deleteGroupAttributes error:', imError); // 删除群属性失败的相关信息
    });
    // 删除全部群属性
    let promise = chat.deleteGroupAttributes({
      groupID: 'group1',
      keyList: []
    });
    promise.then(function(imResponse) { // 删除成功
      console.log(imResponse.data.keyList); // 删除成功的群属性 key 列表
    }).catch(function(imError) { // 删除失败
      console.warn('deleteGroupAttributes error:', imError); // 删除群属性失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群组ID

    keyList Array.<String> required

    群属性 key 列表

    Returns:
    Type
    Promise

    getGroupAttributes(options) → {Promise}

    获取群属性。

    注意1:话题不支持群属性。
    注意2:直播群(AVChatRoom)使用该接口前必须先调用 joinGroup 加群,Public、Meeting、Work、Community 类型群组如果已加群,则不需要再调用 joinGroup
    注意3:keyList 传入非空数组表示获取指定的群属性,传入空数组表示获取全部群属性。

    Examples
    // 获取指定的群属性
    let promise = chat.getGroupAttributes({
      groupID: 'group1',
      keyList: ['key1', 'key2']
    });
    promise.then(function(imResponse) { // 获取成功
      console.log(imResponse.data.groupAttributes); // 指定 key 的群属性
    }).catch(function(imError) { // 获取失败
      console.warn('getGroupAttributes error:', imError); // 获取群属性失败的相关信息
    });
    // 获取全部群属性
    let promise = chat.getGroupAttributes({
      groupID: 'group1',
      keyList: []
    });
    promise.then(function(imResponse) { // 获取成功
      console.log(imResponse.data.groupAttributes); // 全部群属性
    }).catch(function(imError) { // 获取失败
      console.warn('getGroupAttributes error:', imError); // 获取群属性失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群组ID

    keyList Array.<String> required

    群属性 key 列表

    Returns:
    Type
    Promise

    setGroupCounters(options) → {Promise}

    设置群计数器。设置成功后,自己和群组其他成员都会收到 GROUP_COUNTER_UPDATED 事件,您可以通过此接口实现一些常见的计数功能,如点赞计数、直播群礼物计数、观看人数计数等。

    注意1:除了话题,群计数器支持所有的群组类型。
    注意2:使用该接口需要您购买旗舰版套餐。

    Example
    let promise = chat.setGroupCounters({
      groupID: 'group1',
      counters: { key1: 1, key2: 2 }
    });
    promise.then(function(imResponse) { // 设置成功
      console.log(imResponse.data.counters); // 设置成功的群计数器
    }).catch(function(imError) { // 设置失败
      console.warn('setGroupCounters error:', imError); // 设置群计数器失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群组ID

    counters Object required

    群计数器

    Returns:
    Type
    Promise

    increaseGroupCounter(options) → {Promise}

    递增群计数器。更新成功后,自己和群组其他成员都会收到 GROUP_COUNTER_UPDATED 事件。

    注意1:除了话题,群计数器支持所有的群组类型。
    注意2:使用该接口需要您购买旗舰版套餐。

    Example
    let promise = chat.increaseGroupCounter({
      groupID: 'group1',
      key: 'key1',
      value: 1,
    });
    promise.then(function(imResponse) { // 递增成功
      console.log(imResponse.data);
      const { groupID, key, value } = imResponse.data;
    }).catch(function(imError) { // 递增失败
      console.warn('increaseGroupCounter error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群组 ID

    key String required

    群计数器的 key

    value Number required

    群计数器递增的变化量

    Returns:
    Type
    Promise

    decreaseGroupCounter(options) → {Promise}

    递减群计数器。更新成功后,自己和群组其他成员都会收到 GROUP_COUNTERS_UPDATED 事件。

    注意1:除了话题,群计数器支持所有的群组类型。
    注意2:使用该接口需要您购买旗舰版套餐。

    Example
    let promise = chat.decreaseGroupCounter({
      groupID: 'group1',
      key: 'key1',
      value: 2
    });
    promise.then(function(imResponse) { // 递减成功
      console.log(imResponse.data);
      const { groupID, key, value } = imResponse.data;
    }).catch(function(imError) { // 设置失败
      console.warn('decreaseGroupCounter error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群组 ID

    key String required

    群计数器的 key

    value Number required

    群计数器递减的变化量

    Returns:
    Type
    Promise

    getGroupCounters(options) → {Promise}

    获取群计数器。

    注意1:除了话题,群计数器支持所有的群组类型。
    注意2:keyList 传非空数组表示获取指定的群计数器,不传 keyList 表示获取全部群计数器。
    注意3:使用该接口需要您购买旗舰版套餐。

    Examples
    // 获取指定的群计数器
    let promise = chat.getGroupCounters({
      groupID: 'group1',
      keyList: ['key1', 'key2']
    });
    promise.then(function(imResponse) { // 获取成功
      console.log(imResponse.data.counters);
    }).catch(function(imError) {
      console.warn('getGroupCounters error:', imError); // 获取群计数器失败的相关信息
    });
    // 获取全部的群计数器
    let promise = chat.getGroupCounters({ groupID: 'group1' });
    promise.then(function(imResponse) { // 获取成功
      console.log(imResponse.data.counters);
    }).catch(function(imError) { // 获取失败
      console.warn('getGroupCounters error:', imError); // 获取群计数器失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群组ID

    keyList Array.<String> | undefined required

    群计数器 key 列表

    Returns:
    Type
    Promise

    getGroupMemberList(options) → {Promise}

    获取群成员列表。

    注意1:v3.2.0起,如果您购买了旗舰版套餐,此接口返回的群成员资料新增 isOnline 字段,标识成员是否在线。
    注意2:该接口支持拉取群成员禁言截止时间戳(muteUntil),接入侧可根据此值判断群成员是否被禁言,以及禁言的剩余时间。
    注意3:该接口是分页拉取群成员,不能直接用于获取群的总人数。获取群的总人数(memberCount)请使用:getGroupProfile
    注意4:当接口返回的 offset 为 0 时说明群成员已经拉取完成。
    注意5:对直播群(AVChatRoom)增加以下特殊限制:

    • 旗舰版支持拉取最近入群群成员最多 1000 人,新进来的成员排在前面。需要您购买旗舰版套餐且前往 控制台 开启开关。
    • 旗舰版使用该接口时 SDK 会忽略 count 参数,单次查询默认最多返回 500 个群成员。
    • 旗舰版接口调用默认限制 3 秒 1 次请求,如果需要定时查询群成员列表,建议每 10 秒请求一次。
    • 群成员资料信息仅支持 userID | nick | avatar | joinTime | role 字段,设置 nick 和 avatar 信息请调用:updateMyProfile

    注意6:旗舰版支持直播群(AVChatRoom)根据 filter 参数拉取指定标记的群成员列表。标记群成员请参考:markGroupMemberList

    See:
    Examples
    // v3.1.3起支持拉取指定角色的群成员列表,如拉取群的所有管理员
    let promise = chat.getGroupMemberList({ groupID: 'group1', role: TencentCloudChat.GRP_MBR_ROLE_ADMIN, count: 15, offset: 0 }); // 从 0 开始拉取 15 个群成员
    promise.then(function(imResponse) {
      console.log(imResponse.data.memberList); // 群成员列表
    }).catch(function(imError) {
      console.warn('getGroupMemberList error:', imError);
    });
    let promise = chat.getGroupMemberList({ groupID: 'group1', count: 15, offset: 0 }); // 从 0 开始拉取 15 个群成员
    promise.then(function(imResponse) {
      console.log(imResponse.data.memberList); // 群成员列表
    }).catch(function(imError) {
      console.warn('getGroupMemberList error:', imError);
    });
    // 支持拉取群成员禁言截止时间戳。
    let promise = chat.getGroupMemberList({ groupID: 'group1', count: 15, offset: 0 }); // 从 0 开始拉取 15 个群成员
    promise.then(function(imResponse) {
      console.log(imResponse.data.memberList); // 群成员列表
      for (let groupMember of imResponse.data.memberList) {
        if (groupMember.muteUntil * 1000  > Date.now()) {
          console.log(`${groupMember.userID} 禁言中`);
        } else {
          console.log(`${groupMember.userID} 未被禁言`);
        }
      }
    }).catch(function(imError) {
        console.warn('getGroupMemberProfile error:', imError);
    });
    // 支持获取直播群成员在线列表
    let promise = chat.getGroupMemberList({ groupID: 'group1', offset: 0 }); // 从 0 开始拉取,默认一次最多返回 500 个群成员
    promise.then(function(imResponse) {
      console.log(imResponse.data.memberList); // 群成员列表
    }).catch(function(imError) {
      console.warn('getGroupMemberList error:', imError);
    });
    // 支持获取直播群指定标记的在线成员列表
    let promise = chat.getGroupMemberList({ groupID: 'group1', filter: 1000, offset: 0 }); // 从 0 开始拉取,默认一次最多返回 500 个群成员
    promise.then(function(imResponse) {
      console.log(imResponse.data.memberList); // 群成员列表
    }).catch(function(imError) {
      console.warn('getGroupMemberList error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    请求参数

    Properties
    Name Type Default Description
    groupID String required

    群组的 ID

    role String required

    群成员角色。默认 SDK 拉取所有的群成员,您可以通过设置此字段拉取指定角色的群成员列表(v3.1.3起支持),支持的值如下:

    • TencentCloudChat.GRP_MBR_ROLE_OWNER - 群主
    • TencentCloudChat.GRP_MBR_ROLE_ADMIN - 群管理员
    • TencentCloudChat.GRP_MBR_ROLE_MEMBER - 普通群成员
    count Number 15

    需要拉取的数量。最大值:100,避免回包过大导致请求失败。若传入超过100,则只拉取前100个。

    offset Number | String 0

    偏移量,默认从0开始拉取,社群(Community)使用时该字段为 String 类型。

    filter Number

    群成员自定义标记,仅直播群(AVChatRoom)支持

    Returns:
    Type
    Promise

    getGroupMemberProfile(options) → {Promise}

    获取群成员资料,如禁言时间等。

    注意1:TencentCloudChat.TYPES.GRP_AVCHATROOM 类型的群组(即直播群)不支持此操作,错误码 2687。
    注意2:每次查询的用户数上限是50。如果传入的数组长度大于 50,则只取前 50 个用户进行查询,其余丢弃。

    See:
    Example
    let promise = chat.getGroupMemberProfile({
      groupID: 'group1',
      userIDList: ['user1', 'user2'], // 请注意:即使只拉取一个群成员的资料,也需要用数组类型,例如:userIDList: ['user1']
      memberCustomFieldFilter: ['group_member_custom'], // 筛选群成员自定义字段:group_member_custom
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data.memberList); // 群成员列表
    }).catch(function(imError) {
      console.warn('getGroupMemberProfile error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    请求参数

    Properties
    Name Type Description
    groupID String required

    群组 ID

    userIDList Array.<String> required

    要查询的群成员用户 ID 列表

    memberCustomFieldFilter Array.<String>

    群成员自定义字段筛选。可选,若不填,则默认查询所有群成员自定义字段。

    Returns:

    返回Promise对象

    Type
    Promise

    addGroupMember(options) → {Promise}

    添加群成员。详细规则如下:

    • TencentCloudChat.TYPES.GRP_WORK(好友工作群):默认任何群成员都可以直接邀请他人进群,且无需被邀请人同意,直接将其拉入群组中。可将 inviteOption 设置为 TencentCloudChat.TYPES.INVITE_OPTIONS_DISABLE_INVITE 禁止任何群成员邀请他人进群。
    • TencentCloudChat.TYPES.GRP_PUBLIC(陌生人社交群)/ TencentCloudChat.TYPES.GRP_MEETING(临时会议群)/ TencentCloudChat.TYPES.GRP_COMMUNITY(社群):默认不支持群成员邀请他人进群,可通过设置 inviteOption 控制邀请进群选项。
    • TencentCloudChat.TYPES.GRP_AVCHATROOM(直播群):不允许任何人邀请他人入群(包括 App 管理员)。

    注意1:待添加的成员 userID 必须为有效的用户账号,否则接口将返回10019。

    See:
    Examples
    let promise = chat.addGroupMember({groupID: 'group1', userIDList: ['user1','user2','user3']});
    promise.then(function(imResponse) {
      console.log(imResponse.data.successUserIDList); // 添加成功的群成员 userIDList
      console.log(imResponse.data.failureUserIDList); // 添加失败的群成员 userIDList
      console.log(imResponse.data.existedUserIDList); // 已在群中的群成员 userIDList
      // 一个用户 userX 最多允许加入 N 个群,如果已经加入了 N 个群,此时再尝试添加 userX 为群成员,则 userX 不能正常加群
      // SDK 将 userX 的信息放入 overLimitUserIDList,供接入侧处理
      console.log(imResponse.data.overLimitUserIDList); // 超过了“单个用户可加入群组数”限制的用户列表
      console.log(imResponse.data.group); // 添加后的群组信息
    }).catch(function(imError) {
      console.warn('addGroupMember error:', imError); // 错误信息
    });
    // TencentCloudChat.TYPES.GRP_WORK(好友工作群)设置禁止邀请
    chat.updateGroupProfile({
      groupID: 'workTest',
      inviteOption: TencentCloudChat.TYPES.INVITE_OPTIONS_DISABLE_INVITE, // 设置禁止邀请
    }).then(() => {
      // 设置成功后群成员邀请他人进群
      chat.addGroupMember({
        groupID: 'workTest',
        userIDList: ['user1','user2','user3']
      }).catch((error) => {
        if (error.code === 10007) {
          // 群组没有开启邀请进群能力
        }
      });
    })
    // TencentCloudChat.TYPES.GRP_PUBLIC(陌生人社交群)设置自由邀请他人进群,无需群主/群管理员审批
    chat.updateGroupProfile({
      groupID: 'publicTest',
      inviteOption: TencentCloudChat.TYPES.INVITE_OPTIONS_FREE_ACCESS, // 设置自由邀请他人进群
    }).then(() => {
      // 设置成功后群成员邀请他人进群
      let promise = chat.addGroupMember({groupID: 'publicTest', userIDList: ['user1','user2','user3']});
      promise.then(function(imResponse) {
        console.log(imResponse.data.successUserIDList); // 添加成功的群成员 userIDList
        console.log(imResponse.data.failureUserIDList); // 添加失败的群成员 userIDList
        console.log(imResponse.data.existedUserIDList); // 已在群中的群成员 userIDList
        // 一个用户 userX 最多允许加入 N 个群,如果已经加入了 N 个群,此时再尝试添加 userX 为群成员,则 userX 不能正常加群
        // SDK 将 userX 的信息放入 overLimitUserIDList,供接入侧处理
        console.log(imResponse.data.overLimitUserIDList); // 超过了“单个用户可加入群组数”限制的用户列表
        console.log(imResponse.data.group); // 添加后的群组信息
      }).catch(function(imError) {
        console.warn('addGroupMember error:', imError); // 错误信息
      });
    })
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群 ID

    userIDList Array.<String> required

    待添加的群成员 ID 数组,单次最多添加20个成员。

    Returns:
    Type
    Promise

    deleteGroupMember(options) → {Promise}

    删除群成员。群主可移除群成员。

    注意1:旗舰版套餐包支持删除直播群群成员。您可以通过调用此接口实现直播群【封禁群成员】的效果。
    注意2:踢出时长字段仅直播群(AVChatRoom)支持。
    注意3:群成员被移除出直播群后,在【踢出时长内】如果用户想再次进群,需要 APP 管理员调用 restapi 解封。过了【踢出时长】,用户可再次主动加入直播群。

    See:
    Examples
    // 非直播群(AVChatRoom)删除群成员
    let promise = chat.deleteGroupMember({groupID: 'group1', userIDList:['user1'], reason: '你违规了,我要踢你!'});
    promise.then(function(imResponse) {
      console.log(imResponse.data.group); // 删除后的群组信息
      console.log(imResponse.data.userIDList); // 被删除的群成员的 userID 列表
    }).catch(function(imError) {
      console.warn('deleteGroupMember error:', imError); // 错误信息
    });
    // 直播群(AVChatRoom)删除群成员
    let promise = chat.deleteGroupMember({groupID: 'group1', userIDList:['user1'], reason: '你违规了,我要踢你!', duration: 60});
    promise.then(function(imResponse) {
      console.log(imResponse.data.group); // 删除后的群组信息
      console.log(imResponse.data.userIDList); // 被删除的群成员的 userID 列表
    }).catch(function(imError) {
      console.warn('deleteGroupMember error:', imError); // 错误信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群ID

    userIDList Array.<String> required

    待删除的群成员的 ID 列表,单次请求最大支持 20 个群成员

    reason String

    踢人的原因

    duration Number

    踢出时长,在该时间段内被踢用户不能再次加群。单位:秒

    Returns:
    Type
    Promise

    setGroupMemberMuteTime(options) → {Promise}

    设置群成员的禁言时间,可以禁言群成员,也可取消禁言。

    注意1:TencentCloudChat.TYPES.GRP_WORK 类型的群组(即好友工作群)不支持此操作。
    注意2:直播群【封禁】或者【踢出】群成员,需要您购买旗舰版套餐,并调用 deleteGroupMember 接口实现。
    注意3:如果需要【全体禁言】,请参考 updateGroupProfile
    注意4:支持设置社群成员在话题中的禁言时间,groupID 传入 topicID 即可。
    注意5:只有群主和管理员拥有该操作权限:

    • 群主可以禁言/取消禁言管理员和普通群成员。
    • 管理员可以禁言/取消禁言普通群成员。
    See:
    Examples
    let promise = chat.setGroupMemberMuteTime({
      groupID: 'group1',
      userID: 'user1',
      muteTime: 600 // 禁言10分钟;设为0,则表示取消禁言
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data.group); // 修改后的群资料
      console.log(imResponse.data.member); // 修改后的群成员资料
    }).catch(function(imError) {
      console.warn('setGroupMemberMuteTime error:', imError); // 禁言失败的相关信息
    });
    // 设置群成员在话题中的禁言时间
    let promise = chat.setGroupMemberMuteTime({
      groupID: 'topicID',
      userID: 'user1',
      muteTime: 600 // 禁言10分钟;设为0,则表示取消禁言
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data.group); // 修改后的群资料
      console.log(imResponse.data.member); // 修改后的群成员资料
    }).catch(function(imError) {
      console.warn('setGroupMemberMuteTime error:', imError); // 禁言失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群 ID 或 话题 ID

    userID String required

    用户 ID

    muteTime Number required

    禁言时长,单位秒。如设为1000,则表示从现在起禁言该用户1000秒;设为0,则表示取消禁言。

    Returns:
    Type
    Promise

    setGroupMemberRole(options) → {Promise}

    修改群成员角色。只有群主拥有操作的权限。

    注意1:TencentCloudChat.TYPES.GRP_WORK 类型的群组(即好友工作群)和 TencentCloudChat.TYPES.GRP_AVCHATROOM 类型的群组(即直播群)不支持此操作,错误码 2682。

    See:
    Example
    let promise = chat.setGroupMemberRole({
      groupID: 'group1',
      userID: 'user1',
      role: TencentCloudChat.TYPES.GRP_MBR_ROLE_ADMIN // 将群 ID: group1 中的用户:user1 设为管理员
    });
    promise.then(function(imResponse) {
      console.log(imResponse.data.group); // 修改后的群资料
      console.log(imResponse.data.member); // 修改后的群成员资料
    }).catch(function(imError) {
      console.warn('setGroupMemberRole error:', imError); // 错误信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群 ID

    userID String required

    用户 ID

    role String required

    可选值:TencentCloudChat.TYPES.GRP_MBR_ROLE_ADMIN(群管理员),TencentCloudChat.TYPES.GRP_MBR_ROLE_MEMBER(群普通成员),TencentCloudChat.TYPES.GRP_MBR_ROLE_CUSTOM(自定义群成员角色,仅社群支持)

    Returns:
    Type
    Promise

    setGroupMemberNameCard(options) → {Promise}

    设置群成员名片。

    • 群主:可设置所有群成员的名片。
    • 管理员:可设置自身和其他普通群成员的群名片。
    • 普通群成员:只能设置自身群名片。

    注意1:TencentCloudChat.TYPES.GRP_AVCHATROOM 类型的群组(即直播群)不支持此操作,错误码 2687。

    See:
    Example
    let promise = chat.setGroupMemberNameCard({ groupID: 'group1', userID: 'user1', nameCard: '用户名片' });
    promise.then(function(imResponse) {
      console.log(imResponse.data.group); // 设置后的群资料
      console.log(imResponse.data.member); // 修改后的群成员资料
    }).catch(function(imError) {
      console.warn('setGroupMemberNameCard error:', imError); // 设置群成员名片失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群 ID

    userID String

    可选,默认修改自身的群名片

    nameCard String required

    群成员名片

    Returns:
    Type
    Promise

    setGroupMemberCustomField(options) → {Promise}

    设置群成员自定义字段。

    注意1:TencentCloudChat.TYPES.GRP_AVCHATROOM 类型的群组(即直播群)不支持此操作,错误码 2687。
    注意2:普通群成员只能设置自己的自定义字段。

    See:
    Example
    let promise = chat.setGroupMemberCustomField({ groupID: 'group1', memberCustomField: [{key: 'group_member_test', value: 'test'}]});
    promise.then(function(imResponse) {
      console.log(imResponse.data.group); // 修改后的群资料
      console.log(imResponse.data.member); // 修改后的群成员资料
    }).catch(function(imError) {
      console.warn('setGroupMemberCustomField error:', imError); // 设置群成员自定义字段失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群 ID

    userID String

    可选,不填则修改自己的群成员自定义字段

    memberCustomField Array.<Object> required

    群成员自定义字段

    Properties
    Name Type Description
    key String required

    自定义字段的 Key

    value String required

    自定义字段的 Value

    Returns:
    Type
    Promise

    markGroupMemberList(options) → {Promise}

    标记群成员。

    注意1:仅支持直播群(AVChatRoom),且只有群主才有权限标记群组中其他成员。
    注意2:使用该接口需要您购买旗舰版套餐。

    Examples
    let promise = chat.markGroupMemberList({
      groupID: 'group1',
      userIDList: ['user1', 'user2'],
      markType: 1000,
      enableMark: true,
    });
    promise.then(function(imResponse) {
      // 标记成功
      const { successUserIDList, failureUserIDList } = imResponse.data;
      // successUserIDList - 标记成功的 userID 列表
      // failureUserIDList - 标记失败的 userID 列表
    }).catch(function(imError) {
      console.warn('markGroupMemberList error:', imError); // 标记群成员失败的相关信息
    });
    // 获取直播群指定标记的在线成员列表
    let promise = chat.getGroupMemberList({ groupID: 'group1', filter: 1000, offset: 0 }); // 从 0 开始拉取,默认一次最多返回 500 个群成员
    promise.then(function(imResponse) {
      console.log(imResponse.data.memberList); // 群成员列表
    }).catch(function(imError) {
      console.warn('getGroupMemberList error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    群组 ID。

    userIDList Array required

    群成员 userID 列表,单次请求最多 500 个群成员。

    markType Number required

    标记类型。大于等于 1000,您可以自定义,一个直播群里最多允许定义 10 个标记。

    enableMark Boolean required

    true 表示添加标记,false 表示移除标记。

    Returns:
    Type
    Promise

    getJoinedCommunityList() → {Promise}

    获取支持话题的社群列表。

    注意1:该接口仅适用于获取支持话题的社群,需 购买旗舰版套餐包 并在 控制台 >【功能配置】>【群组配置】>【群功能配置】> 社群 打开开关后方可使用。

    Example
    // 获取支持话题的社群列表
    let promise = chat.getJoinedCommunityList();
    promise.then(function(imResponse) { // 获取成功
      console.log(imResponse.data.groupList); // 支持话题的社群列表
    }).catch(function(imError) { // 获取失败
      console.warn('getJoinedCommunityList error:', imError); // 失败的相关信息
    });
    Returns:
    Type
    Promise

    createTopicInCommunity(options) → {Promise}

    创建话题。

    注意1:该接口仅适用于支持话题的社群,需 购买旗舰版套餐包控制台 > 【功能配置】>【群组配置】>【群功能配置】> 社群 页面,完成开通社群后,再打开开通话题开关,方可使用。
    注意2:调用该接口前必须先调用 createGroup 创建支持话题的社群。

    Examples
    // 创建支持话题的社群
    let promise = chat.createGroup({
      type: TencentCloudChat.TYPES.GRP_COMMUNITY,
      name: 'WebSDK',
      isSupportTopic: true
    });
    promise.then(function(imResponse) { // 创建成功
      console.log(imResponse.data.group); // 创建的群的资料,包含 groupID 等信息
    }).catch(function(imError) {
      console.warn('createGroup error:', imError); // 创建群组失败的相关信息
    });
    // 在社群下创建话题
    let promise = chat.createTopicInCommunity({
      groupID: 'group1',
      topicName: 'test',
      avatar: 'xxx',
      notification: 'xxx',
      introduction: 'xxx',
      customData: 'xxxx'
    });
    promise.then(function(imResponse) { // 创建成功
      console.log(imResponse.data.topicID); // 话题 ID
    }).catch(function(imError) { // 创建失败
      console.warn('createTopicInCommunity error:', imError); // 创建话题失败的相关信息
    });
    // 向话题(Topic)发消息
    let message = chat.createTextMessage({
      to: '@TGS#_@TGS#cWWFWHIM62CL@TOPIC#_@TOPIC#cXWFWHIM62CR', // 话题 ID
      conversationType: TencentCloudChat.TYPES.CONV_GROUP,
      payload: {
        text: 'Hello world!'
      },
    });
    // 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    话题所属社群 ID

    topicName String required

    话题名称

    topicID String required

    自定义话题 ID 时,格式必须是社群 ID 拼接上自定义话题 ID。如:@TGS#_xxx@TOPIC#_xxx

    avatar String required

    话题头像

    notification String required

    话题公告

    introduction String required

    话题简介

    customData String required

    话题自定义信息

    Returns:
    Type
    Promise

    deleteTopicFromCommunity(options) → {Promise}

    删除话题。

    注意1:该接口仅适用于支持话题的社群。

    Examples
    // 删除某个社群下指定话题
    let promise = chat.deleteTopicFromCommunity({
      groupID: 'group1',
      topicIDList: ['topicID'],
    });
    promise.then(function(imResponse) { // 删除成功
      const { successTopicList, failureTopicList } = imResponse.data;
      // 删除成功的话题列表
      successTopicList.forEach((item) => {
         const { topicID } = item;
      });
      // 删除失败的话题列表
      failureTopicList.forEach((item) => {
         const { topicID, code, message } = item;
      })
    }).catch(function(imError) { // 删除失败
      console.warn('deleteTopicFromCommunity error:', imError); // 删除话题失败的相关信息
    });
    // 删除某个社群下所有话题
    let promise = chat.deleteTopicFromCommunity({
      groupID: 'group1',
    });
    promise.then(function(imResponse) { // 删除成功
      const { successTopicList, failureTopicList } = imResponse.data;
      // 删除成功的话题列表
      successTopicList.forEach((item) => {
         const { topicID } = item;
      });
      // 删除失败的话题列表
      failureTopicList.forEach((item) => {
         const { topicID, code, message } = item;
      })
    }).catch(function(imError) { // 删除失败
      console.warn('deleteTopicFromCommunity error:', imError); // 删除话题失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    话题所属社群 ID

    topicIDList Array | undefined required

    话题 ID 列表,不传 topicIDList 表示删除全部话题

    Returns:
    Type
    Promise

    updateTopicProfile(options) → {Promise}

    更新话题资料。

    注意1:该接口仅适用于支持话题的社群。
    注意2:话题内其他成员可以收到 TencentCloudChat.EVENT.TOPIC_UPDATED 事件。

    Example
    // 更新话题资料
    let promise = chat.updateTopicProfile({
      groupID: 'group1',
      topicID: 'topic1',
      topicName: 'test',
      avatar: 'xxx'
      notification: 'xxx',
      introduction: 'xxx',
      customData: 'xxxx',
      muteAllMembers: true
    });
    promise.then(function(imResponse) { // 设置话题资料成功
      console.log(imResponse.data.topic); // 返回修改后的话题资料
    }).catch(function(imError) { // 设置话题资料失败
      console.warn('updateTopicProfile error:', imError); // 设置话题资料失败的相关信息
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    必填,话题所属社群 ID

    topicID String required

    必填,话题 ID

    topicName String required

    话题名称

    avatar String required

    话题头像

    notification String required

    话题公告

    introduction String required

    话题简介

    customData String required

    话题自定义信息

    muteAllMembers Boolean required

    设置全体禁言,true - 全体禁言 false - 取消全体禁言

    Returns:
    Type
    Promise

    getTopicList(options) → {Promise}

    获取话题列表。

    注意1:该接口仅适用于支持话题的社群。

    Examples
    // 获取指定的话题
    let promise = chat.getTopicList({
      groupID: 'group1',
      topicIDList: ['topicID'],
    });
    promise.then(function(imResponse) { // 获取成功
      const { successTopicList, failureTopicList } = imResponse.data;
      // 获取成功的话题列表
      successTopicList.forEach((item) => {
         const { topicID } = item;
      });
      // 获取失败的话题列表
      failureTopicList.forEach((item) => {
         const { topicID, code, message } = item;
      })
    }).catch(function(imError) { // 获取失败
      console.warn('getTopicList error:', imError); // 获取话题列表失败的相关信息
    });
    // 获取全部的话题
    let promise = chat.getTopicList({
      groupID: 'group1',
    });
    promise.then(function(imResponse) { // 获取成功
      const { successTopicList, failureTopicList } = imResponse.data;
      // 获取成功的话题列表
      successTopicList.forEach((item) => {
         const { topicID } = item;
      });
      // 获取失败的话题列表
      failureTopicList.forEach((item) => {
         const { topicID, code, message } = item;
      })
    }).catch(function(imError) { // 获取失败
      console.warn('getTopicList error:', imError); // 获取话题列表失败的相关信息
    });
    // 向话题(Topic)发消息
    let message = chat.createTextMessage({
      to: '@TGS#_@TGS#cWWFWHIM62CL@TOPIC#_@TOPIC#cXWFWHIM62CR', // 话题 ID
      conversationType: TencentCloudChat.TYPES.CONV_GROUP,
      payload: {
        text: 'Hello world!'
      },
    });
    // 发送消息
    let promise = chat.sendMessage(message);
    promise.then(function(imResponse) {
      // 发送成功
      console.log(imResponse);
    }).catch(function(imError) {
      // 发送失败
      console.warn('sendMessage error:', imError);
    });
    // 同步获取已加入社群下的所有话题
    async function getTopicListSync (groupList) {
     for (let i = 0; i < groupList.length; i++) {
        const { groupID } = groupList[i];
        await chat.getTopicList({ groupID }).then(function(imResponse){
          const { successTopicList, failureTopicList } = imResponse.data;
          // successTopicList - 获取成功的话题列表
          // failureTopicList - 获取失败的话题列表
        }).catch(function(imError) {
          console.warn('getTopicListSync error:', imError);
        })
      }
    }
    // 拉取到已加入的社群(支持话题)列表后调用 getTopicListSync 方法
    chat.getJoinedCommunityList().then((imResponse) => {
      const { groupList = [] } = imResponse.data;
      getTopicListSync(groupList);
    })
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Description
    groupID String required

    话题所属社群 ID

    topicIDList Array | undefined required

    话题 ID 列表,不传 topicIDList 表示获取全部话题

    Returns:
    Type
    Promise

    addSignalingListener(eventName, handler, contextopt)

    监听信令事件。

    注意1:集成 ESM 规范的 SDK 时,需同时集成 SignalingModule,请参考 集成指引
    注意2:请在调用 login 接口前调用此接口监听事件,避免漏掉 SDK 派发的事件。

    Example
    let onNewInvitationReceived = function(event) {
    };
    chat.addSignalingListener(TencentCloudChat.TSignaling.NEW_INVITATION_RECEIVED, onNewInvitationReceived);
    Parameters:
    Name Type Description
    eventName String required

    事件名称。所有的事件名称都存放在 TencentCloudChat.TSignaling 变量中,如需要查看可以使用 console.log(TencentCloudChat.TSignaling) 把所有的事件显示出来。事件列表

    handler function required

    处理事件的方法,当事件触发时,会调用此handler进行处理。

    context *

    期望 handler 执行时的上下文

    removeSignalingListener(eventName, handler, contextopt)

    移除监听信令事件。

    注意:集成 ESM 规范的 SDK 时,需同时集成 SignalingModule,请参考 集成指引

    Example
    let onNewInvitationReceived = function(event) {
    };
    chat.removeSignalingListener(TencentCloudChat.TSignaling.NEW_INVITATION_RECEIVED, onNewInvitationReceived);
    Parameters:
    Name Type Description
    eventName String required

    事件名称。所有的事件名称都存放在 TencentCloudChat.TSignaling 变量中,如需要查看可以使用 console.log(TencentCloudChat.TSignaling) 把所有的事件显示出来。事件列表

    handler function required

    处理事件的方法,当事件触发时,会调用此handler进行处理。

    context *

    期望 handler 执行时的上下文

    invite(options) → {Promise}

    邀请某个人。

    注意:集成 ESM 规范的 SDK 时,需同时集成 SignalingModule,请参考 集成指引

    Examples
    // 邀请某个人
    let promise = chat.invite({
      userID: 'user1',
      data: ''
    });
    promise.then(function(imResponse) { // 发送邀请信令成功
     console.warn('invite success:', imResponse)
    }).catch(function(imError) {
      console.warn('invite error:', imError);
    });
    // 邀请某个人, 设置不更新会话 unreadCount 和 lastMessage
    let promise = chat.invite({
      userID: 'user1',
      data: JSON.stringify({ excludeFromHistoryMessage: true }), // excludeFromHistoryMessage: true,表示此信令消息不更新会话 unreadCount 和 lastMessage
    });
    promise.then(function(imResponse) { // 发送邀请信令成功
     console.warn('invite success:', imResponse)
    }).catch(function(imError) {
      console.warn('invite error:', imError);
    });
    // 邀请某个人, 并设置 30s 超时, 30s 内没有任何操作,邀请方会收到 TencentCloudChat.TSignaling.INVITATION_TIMEOUT 事件。
    let promise = chat.invite({
      userID: 'user1',
      data: '',
      timeout: 30 // 设置 30s 超时
    });
    promise.then(function(imResponse) { // 发送邀请信令成功
     console.warn('invite success:', imResponse)
    }).catch(function(imError) {
      console.warn('invite error:', imError);
    });
    // 邀请某个人, 设置 30s 超时, 相关信令不存入漫游, 且不会进行离线推送
    let promise = chat.invite({
      userID: 'user1',
      data: '',
      timeout: 30, // 设置 30s 超时
      onlineUserOnly: true // 设置相关信令不存入漫游, 且不会进行离线推送
    });
    promise.then(function(imResponse) { // 发送邀请信令成功
     console.warn('invite success:', imResponse)
    }).catch(function(imError) {
      console.warn('invite error:', imError);
    });
    // 邀请某个人, 设置 30s 超时, 设置离线消息推送
    let promise = chat.invite({
      userID: 'user1',
      data: '',
      timeout: 30, // 设置 30s 超时
      offlinePushInfo: {
         disablePush: false, // 如果接收方不在线,则进行离线推送
         disableVoipPush: false, // 开启 voip 推送需要同时开启离线推送
         title: '', // 离线推送标题
         description: '', // 离线推送内容
         androidOPPOChannelID: '' // 离线推送设置 OPPO 手机 8.0 系统及以上的渠道 ID
       }
    });
    promise.then(function(imResponse) { // 发送邀请信令成功
     console.warn('invite success:', imResponse)
    }).catch(function(imError) {
      console.warn('invite error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    userID String required

    邀请的用户 ID

    data String ""

    自定义数据

    timeout Number 0

    超时时间,单位秒,如果设置为 0,SDK 不会做超时检测,也不会触发 onInvitationTimeout 回调

    onlineUserOnly Boolean false

    消息是否仅发送给在线用户的标识,默认值为 false;设置为 true,则消息既不存漫游,也不会计入未读,也不会离线推送给接收方, 并且 invite 操作也不会产生历史消息(针对该次 invite 的后续 cancel、accept、reject、timeout 操作也同样不会产生历史消息)

    offlinePushInfo Object

    离线推送配置

    Properties
    Name Type Description
    disablePush Boolean

    true 关闭离线推送;false 开启离线推送(默认)

    disableVoipPush Boolean

    true 关闭 voip 推送(默认);false 开启 voip 推送(开启 voip 推送需要同时开启离线推送)

    title String

    离线推送标题。该字段为 iOS 和 Android 共用

    description String

    离线推送内容。该字段会覆盖消息实例的离线推送展示文本。

    extension String

    离线推送透传内容

    ignoreIOSBadge Boolean

    离线推送忽略 badge 计数(仅对 iOS 生效),如果设置为 true,在 iOS 接收端,这条消息不会使 APP 的应用图标未读计数增加

    androidOPPOChannelID String

    离线推送设置 OPPO 手机 8.0 系统及以上的渠道 ID

    Returns:
    Type
    Promise

    inviteInGroup(options) → {Promise}

    邀请群内的某些人。

    注意:集成 ESM 规范的 SDK 时,需同时集成 SignalingModule,请参考 集成指引

    Examples
    // 邀请群内的某些人
    let promise = chat.inviteInGroup({
      groupID: 'AV1',
      inviteeList: ['user1', 'user2'],
      data: '',
    });
    promise.then(function(imResponse) { // 发送邀请信令成功
     console.warn('inviteInGroup success:', imResponse)
    }).catch(function(imError) {
      console.warn('inviteInGroup error:', imError);
    });
    // 邀请群内的某些人, 设置不更新会话 unreadCount 和 lastMessage
    let promise = chat.inviteInGroup({
      groupID: 'AV1',
      inviteeList: ['user1', 'user2'],
      data: JSON.stringify({ excludeFromHistoryMessage: true }), // excludeFromHistoryMessage: true,表示此信令消息不更新会话 unreadCount 和 lastMessage
    });
    promise.then(function(imResponse) { // 发送邀请信令成功
     console.warn('inviteInGroup success:', imResponse)
    }).catch(function(imError) {
      console.warn('inviteInGroup error:', imError);
    });
    // 邀请群内的某些人, 并设置 30s 超时, 30s 内没有任何操作,邀请方会收到 TencentCloudChat.TSignaling.INVITATION_TIMEOUT 事件。
    let promise = chat.inviteInGroup({
      groupID: 'AV1',
      inviteeList: ['user1', 'user2'],
      data: '',
      timeout: 30,
    });
    promise.then(function(imResponse) { // 发送邀请信令成功
     console.warn('inviteInGroup success:', imResponse)
    }).catch(function(imError) {
      console.warn('inviteInGroup error:', imError);
    });
    // 邀请群内的某些人, 设置 30s 超时, 相关信令不存入漫游, 且不会进行离线推送
    let promise = chat.inviteInGroup({
      groupID: 'AV1',
      inviteeList: ['user1', 'user2'],
      data: '',
      timeout: 30, // 设置 30s 超时
      onlineUserOnly: true // 设置相关信令不存入漫游, 且不会进行离线推送
    });
    promise.then(function(imResponse) { // 发送邀请信令成功
     console.warn('inviteInGroup success:', imResponse)
    }).catch(function(imError) {
      console.warn('inviteInGroup error:', imError);
    });
    // 邀请群内的某些人, 设置 30s 超时, 设置离线消息推送
    let promise = chat.inviteInGroup({
      groupID: 'AV1',
      inviteeList: ['user1', 'user2'],
      data: '',
      timeout: 30, // 设置 30s 超时
      offlinePushInfo: {
         disablePush: false, // 如果接收方不在线,则进行离线推送
         disableVoipPush: false, // 开启 voip 推送需要同时开启离线推送
         title: '', // 离线推送标题
         description: '', // 离线推送内容
         androidOPPOChannelID: '' // 离线推送设置 OPPO 手机 8.0 系统及以上的渠道 ID
       }
    });
    promise.then(function(imResponse) { // 发送邀请信令成功
     console.warn('inviteInGroup success:', imResponse)
    }).catch(function(imError) {
      console.warn('inviteInGroup error:', imError);
    });
    Parameters:
    Name Type Description
    options Object required

    参数选项

    Properties
    Name Type Default Description
    groupID String required

    群组 ID

    inviteeList Array.<String> required

    被邀请人列表

    data String ""

    自定义数据

    timeout Number 0

    超时时间,单位秒,如果设置为 0,SDK 不会做超时检测,也不会触发 onInvitationTimeout 回调

    onlineUserOnly Boolean false

    消息是否仅发送给在线用户的标识,默认值为 false;设置为 true,则消息既不存漫游,也不会计入未读,也不会离线推送给接收方, 并且 invite 操作也不会产生历史消息(针对该次 invite 的后续 cancel、accept、reject、timeout 操作也同样不会产生历史消息)

    offlinePushInfo Object

    离线推送配置

    Properties
    Name Type Description
    disablePush Boolean

    true 关闭离线推送;false 开启离线推送(默认)

    disableVoipPush Boolean

    true 关闭 voip 推送(默认);false 开启 voip 推送(开启 voip 推送需要同时开启离线推送)

    title String

    离线推送标题。该字段为 iOS 和 Android 共用

    description String

    离线推送内容。该字段会覆盖消息实例的离线推送展示文本。

    extension String

    离线推送透传内容

    ignoreIOSBadge Boolean

    离线推送忽略 badge 计数(仅对 iOS 生效),如果设置为 true,在 iOS 接收端,这条消息不会使 APP 的应用图标未读计数增加

    androidOPPOChannelID String

    离线推送设置 OPPO 手机 8.0 系统及以上的渠道 ID

    Returns:
    Type
    Promise

    cancel(options) → {Promise}

    邀请发起者取消邀请。

    注意:集成 ESM 规范的 SDK 时,需同时集成 SignalingModule,请参考 集成指引

    Example
    // 邀请发起者取消邀请
    let promise = chat.cancel({
      inviteID: '38897dbf-ecd4-4b59-a132-bc31529a2b18',
      data: '',
    })
    promise.then(function(imResponse) { // 取消邀请成功
     console.log('cancel OK', imResponse);
    }).catch(function(error) {
      console.warn('cancel failed:', error); // 取消邀请失败
    });
    Parameters:
    Name Type Description
    options Object required

    配置

    Properties
    Name Type Default Description
    inviteID String required

    邀请信息的ID

    data String ""

    自定义数据

    Returns:
    Type
    Promise

    accept(options) → {Promise}

    被邀请人接受邀请。

    注意:集成 ESM 规范的 SDK 时,需同时集成 SignalingModule,请参考 集成指引

    Example
    // 被邀请人接受邀请
    let promise = chat.accept({
      inviteID: '38897dbf-ecd4-4b59-a132-bc31529a2b18',
      data: '',
    })
    promise.then(function(imResponse) { // 被邀请人接受邀请成功
     console.log('accept OK', imResponse);
    }).catch(function(error) {
      console.warn('accept failed:', error); // 被邀请人接受邀请失败
    });
    Parameters:
    Name Type Description
    options Object required

    配置

    Properties
    Name Type Default Description
    inviteID String required

    邀请信息的ID

    data String ""

    自定义数据

    Returns:
    Type
    Promise

    reject(options) → {Promise}

    被邀请人拒绝邀请。

    注意:集成 ESM 规范的 SDK 时,需同时集成 SignalingModule,请参考 集成指引

    Example
    // 被邀请人拒绝邀请
    let promise = chat.reject({
      inviteID: '38897dbf-ecd4-4b59-a132-bc31529a2b18',
      data: '',
    })
    promise.then(function(imResponse) { // 被邀请人拒绝邀请成功
     console.log('reject OK', imResponse);
    }).catch(function(error) {
      console.warn('reject failed:', error); // 被邀请人拒绝邀请失败
    });
    Parameters:
    Name Type Description
    options Object required

    配置

    Properties
    Name Type Default Description
    inviteID String required

    邀请信息的ID

    data String ""

    自定义数据

    Returns:
    Type
    Promise

    getSignalingInfo(message) → {Signaling|null}

    获取信令信息。

    注意:集成 ESM 规范的 SDK 时,需同时集成 SignalingModule,请参考 集成指引

    Example
    // 获取信令信息
    let signaling = chat.getSignalingInfo(message);
    console.log('signaling info', signaling); // signaling 为 null 时,表示该条消息为普通消息,不是信令消息
    Parameters:
    Name Type Description
    message Message required

    消息对象

    Returns:
    Type
    Signaling | null

    modifyInvitation(options) → {Promise}

    修改邀请信令。

    注意1:集成 ESM 规范的 SDK 时,需同时集成 SignalingModule,请参考 集成指引
    注意2:仅支持修改邀请信令的自定义字段 data。当邀请信令的 onlineUserOnly = true 时,不支持修改。

    Example
    // 修改邀请信令
    let promise = chat.modifyInvitation({
      inviteID:'38897dbf-ecd4-4b59-a132-bc31529a2b18',
      data: 'xxxx'
    });
    promise.then(function(imResponse) { // 修改发送邀请信令成功
     console.log('modifyInvitation OK', imResponse);
    }).catch(function(error) {
      console.warn('modifyInvitation failed:', error); // 修改邀请信令失败
    });
    Parameters:
    Name Type Description
    options Object required

    配置

    Properties
    Name Type Description
    inviteID String required

    邀请信息的ID

    data String required

    自定义数据

    Returns:
    Type
    Promise