new 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'; |
| |
| |
| let options = { |
| SDKAppID: 0 |
| }; |
| let chat = TencentCloudChat.create(options); |
| |
| chat.setLogLevel(0); |
| |
| |
| |
| chat.registerPlugin({'tim-upload-plugin': TIMUploadPlugin}); |
| |
| |
| |
| |
| |
| chat.on(TencentCloudChat.EVENT.SDK_READY, function(event) { |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, function(event) { |
| |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.MESSAGE_MODIFIED, function(event) { |
| |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.MESSAGE_REVOKED, function(event) { |
| |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.MESSAGE_READ_BY_PEER, function(event) { |
| |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED, function(event) { |
| |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.GROUP_LIST_UPDATED, function(event) { |
| |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.PROFILE_UPDATED, function(event) { |
| |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.BLACKLIST_UPDATED, function(event) { |
| |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.SDK_NOT_READY, function(event) { |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.KICKED_OUT, function(event) { |
| |
| |
| |
| |
| |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.NET_STATE_CHANGE, function(event) { |
| |
| |
| |
| |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, function(event) { |
| |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.FRIEND_APPLICATION_LIST_UPDATED, function(event) { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| }); |
| |
| chat.on(TencentCloudChat.EVENT.FRIEND_GROUP_LIST_UPDATED, function(event) { |
| |
| |
| |
| }); |
| |
| |
| 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,【消息服务 Chat】>【功能配置】>【登录与消息】>【登录设置】>【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
登出即时通信 IM,通常在切换账号的时候调用,清除登录态以及内存中的所有数据。
注意1:调用此接口的实例会发布 SDK_NOT_READY
事件,此时该实例下线,无法收、发消息。
注意2:如果您在即时通信 IM 控制台配置的“Web端实例同时在线个数”大于 1,且同一账号登录了a1
和a2
两个实例(含小程序端),当执行a1.logout()
后,a1
会下线,无法收、发消息。而a2
实例不会受影响。
注意3:多实例被踢:基于第 2 点,如果“Web端实例同时在线个数”配置为 2,且您的某一账号已经登录了 a1
,a2
两个实例,当使用此账号成功登录第三个实例a3
时,a1
或a2
中的一个实例会被踢下线(通常是最先处在登录态的实例会触发),这种情况称之为**“多实例被踢”**。假设a1
实例被踢下线,a1
实例内部会执行登出流程,然后抛出KICKED_OUT
事件,接入侧可以监听此事件,并在触发时跳转到登录页。此时a1
实例下线,而a2
、a3
实例可以正常运行。
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}
Example
const userID = chat.getLoginUser();
Returns:
已登录返回登录用户的 userID,未登录返回 ''。
-
Type
-
String
getServerTime() → {Number}
Example
const serverTime = chat.getServerTime();
Returns:
-
Type
-
Number
isReady() → {Boolean}
SDK 是否 ready。SDK ready 后,开发者可调用 SDK 发送消息等 API,使用 SDK 的各项功能。
开发者也可以监听:
Example
let isReady = chat.isReady();
Returns:
-
Type
-
Boolean
销毁 SDK 实例。SDK 会先 logout,然后断开 WebSocket 长连接,并释放资源
Example
let promise = chat.destroy();
Returns:
-
Type
-
Promise
on(eventName, handler, contextopt)
监听事件。
注意:请在调用 login 接口前调用此接口监听事件,避免漏掉 SDK 派发的事件。
Example
| let onMessageReceived = function(event) { |
| |
| |
| |
| }; |
| 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) { |
| |
| |
| |
| }; |
| 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:在 React Native 项目中使用 tim-upload-plugin,需要在将 tim-upload-plugin 升级到 v1.3.1 以上的版本,同时为了提升弱网环境或网络切换时的使用体验,您需要注册网络状态监听插件@react-native-community/netinfo。
注意3:uni-app 打包终端应用,推送插件请使用 uni-app 腾讯云推送服务(Push)。
注意4:react-native 打包终端应用,推送插件请使用 react-native 腾讯云推送服务(Push)。
注意5:推送插件的配置文件可以在IM控制台 > 推送管理 > 接入设置进行下载 。
注意6:在 React Native 打包的 App 中发送富媒体消息,需要添加权限:
- 在 Android 项目的
AndroidManifest.xml
中添加以下权限:
| <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
| <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> |
| <uses-permission android:name="android.permission.RECORD_AUDIO" /> |
- 在 iOS 项目的
Info.plist
中添加以下权限:
| <key>NSCameraUsageDescription</key> |
| <string>我们需要访问您的相机以拍摄照片</string> |
| <key>NSPhotoLibraryUsageDescription</key> |
| <string>我们需要访问您的相册以选择照片</string> |
| <key>NSMicrophoneUsageDescription</key> |
| <string>我们需要访问您的麦克风以录制音频</string> |
Examples
| |
| chat.registerPlugin({'tim-upload-plugin': TIMUploadPlugin}); |
| |
| |
| npm install @react-native-community/netinfo --save |
| |
| import NetInfo from "@react-native-community/netinfo"; |
| |
| chat.registerPlugin({'chat-network-monitor': NetInfo}); |
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
| |
| |
| let message = chat.createTextMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| |
| |
| |
| payload: { |
| text: 'Hello world!' |
| }, |
| |
| 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: 'test', |
| conversationType: TencentCloudChat.TYPES.CONV_GROUP, |
| payload: { |
| text: 'Hello world!' |
| }, |
| |
| 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', |
| conversationType: TencentCloudChat.TYPES.CONV_GROUP, |
| payload: { |
| text: 'Hello world!' |
| }, |
| |
| 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@TOPIC#_@TOPIC#cXWFWHIM62CR', |
| 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); |
| }); |
| |
| |
| let message = chat.createTextMessage({ |
| to: 'test', |
| conversationType: TencentCloudChat.TYPES.CONV_GROUP, |
| payload: { |
| text: 'Hello world!' |
| }, |
| |
| 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 |
| }); |
| |
| 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
| |
| |
| let message = chat.createTextAtMessage({ |
| to: 'group1', |
| conversationType: TencentCloudChat.TYPES.CONV_GROUP, |
| |
| |
| |
| payload: { |
| text: '@denny @lucy @所有人 今晚聚餐,收到的请回复1', |
| atUserList: ['denny', 'lucy', TencentCloudChat.TYPES.MSG_AT_ALL] |
| }, |
| |
| |
| }); |
| |
| 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 参数的描述。
注意3:支持的图片类型:'jpg', 'jpeg', 'gif', 'png', 'bmp', 'image', 'webp'。
Examples
| |
| |
| let message = chat.createImageMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| |
| |
| |
| payload: { |
| file: document.getElementById('imagePicker'), |
| }, |
| |
| |
| onProgress: function(event) { console.log('file uploading:', event) } |
| }); |
| |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| |
| |
| 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]; |
| |
| fileCopy = file.slice(); |
| } |
| |
| if (typeof file === 'undefined') { |
| console.warn('file 是 undefined,请检查代码或浏览器兼容性!'); |
| return; |
| } |
| |
| |
| let message = chat.createImageMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| payload: { |
| file: file |
| }, |
| onProgress: function(event) { console.log('file uploading:', event) } |
| }); |
| |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| }); |
| |
| |
| wx.chooseMedia({ |
| mediaType: ['image'], |
| sourceType: ['album'], |
| count: 1, |
| 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) } |
| }); |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| } |
| }) |
| |
| |
| |
| 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) } |
| }); |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| } |
| }); |
| |
| import {launchCamera, launchImageLibrary} from 'react-native-image-picker'; |
| |
| |
| launchImageLibrary({ |
| mediaType: 'photo', |
| selectionLimit: 1, |
| }).then((result) => { |
| const file = result.assets[0]; |
| |
| let message = chat.createImageMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| payload: { file: file }, |
| |
| |
| }); |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| }); |
| |
| |
| launchCamera({ |
| mediaType: 'photo', |
| cameraType: 'back', |
| }).then((result) => { |
| const file = result.assets[0]; |
| |
| let message = chat.createImageMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| payload: { file: file }, |
| |
| |
| }); |
| |
| 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
| |
| |
| const recorderManager = wx.getRecorderManager(); |
| |
| |
| const recordOptions = { |
| duration: 60000, |
| sampleRate: 44100, |
| numberOfChannels: 1, |
| encodeBitRate: 192000, |
| format: 'aac' |
| }; |
| |
| |
| recorderManager.onError(function(errMsg) { |
| console.warn('recorder error:', errMsg); |
| }); |
| |
| recorderManager.onStop(function(res) { |
| console.log('recorder stop', res); |
| |
| |
| const message = chat.createAudioMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| |
| |
| |
| payload: { |
| file: res |
| }, |
| |
| |
| |
| onProgress: function(event) { console.log('file uploading:', event) } |
| }); |
| |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| }); |
| |
| |
| recorderManager.start(recordOptions); |
| |
| |
| |
| let recorder = new Recorder({ |
| sampleBits: 16, |
| sampleRate: 16000, |
| numChannels: 1, |
| }); |
| let startTs; |
| recorder.start().then(() => { |
| |
| startTs = Date.now(); |
| }, (error) => { |
| |
| console.log(`${error.name} : ${error.message}`); |
| }); |
| |
| |
| recorder.stop(); |
| |
| |
| let duration = Date.now() - startTs; |
| let wavBlob = recorder.getWAVBlob(); |
| |
| |
| let audioFile = new File([wavBlob], 'hello.wav', { type: 'wav' }); |
| audioFile.duration = duration; |
| |
| |
| let message = chat.createAudioMessage({ |
| to: 'user1', |
| conversationType: 'C2C', |
| payload: { |
| file: audioFile |
| }, |
| |
| onProgress: function(event) { console.log('file uploading:', event) } |
| }); |
| |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| |
| import AudioRecorderPlayer from 'react-native-audio-recorder-player'; |
| |
| |
| let duration = 0; |
| |
| let uri = ''; |
| |
| |
| const onStartRecord = async () => { |
| await audioRecorderPlayer.startRecorder(); |
| audioRecorderPlayer.addRecordBackListener((e: any) => { |
| duration = e.currentPosition; |
| }); |
| }; |
| |
| const onStopRecord = async () => { |
| uri = await audioRecorderPlayer.stopRecorder(); |
| audioRecorderPlayer.removeRecordBackListener(); |
| }; |
| |
| const file = { |
| uri: uri, |
| duration: duration, |
| }; |
| let message = chat.createAudioMessage({ |
| to: 'user1', |
| conversationType: 'C2C', |
| payload: { |
| file: file, |
| }, |
| |
| |
| }); |
| 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 参数的描述。
注意3:支持的视频类型:'mp4', 'quicktime', 'mov'。
Examples
| |
| |
| wx.chooseMedia({ |
| mediaType: ['video'], |
| sourceType: ['album', 'camera'], |
| maxDuration: 60, |
| camera: 'back', |
| success (res) { |
| |
| let message = chat.createVideoMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| |
| |
| |
| payload: { |
| file: res |
| }, |
| |
| |
| |
| onProgress: function(event) { console.log('file uploading:', event) } |
| }) |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| } |
| }) |
| |
| |
| |
| const message = chat.createVideoMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| payload: { |
| file: document.getElementById('videoPicker') |
| }, |
| onProgress: function(event) { console.log('file uploading:', event) } |
| }); |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| |
| |
| |
| uni.chooseMedia({ |
| mediaType: ['video'], |
| count: 1, |
| sourceType: ['camera', 'album'], |
| maxDuration: 60, |
| 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) } |
| }); |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| } |
| }) |
| |
| import {launchCamera, launchImageLibrary} from 'react-native-image-picker'; |
| |
| |
| launchImageLibrary({ |
| mediaType: 'video', |
| selectionLimit: 1, |
| }).then((result) => { |
| const file = result.assets[0]; |
| |
| let message = chat.createVideoMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| payload: { file: file }, |
| |
| |
| }); |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| }); |
| |
| |
| launchCamera({ |
| mediaType: 'video', |
| cameraType: 'back', |
| }).then((result) => { |
| const file = result.assets[0]; |
| |
| let message = chat.createVideoMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| payload: { file: file }, |
| |
| |
| }); |
| |
| 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
| |
| |
| function random(min, max) { |
| return Math.floor(Math.random() * (max - min + 1) + min); |
| } |
| |
| let message = chat.createCustomMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| |
| |
| |
| payload: { |
| data: 'dice', |
| description: String(random(1,6)), |
| extension: '' |
| } |
| }); |
| |
| 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
| |
| |
| let message = chat.createFaceMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| |
| |
| |
| payload: { |
| index: 1, |
| data: 'tt00' |
| }, |
| |
| |
| }); |
| |
| 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
| |
| |
| let message = chat.createFileMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| |
| |
| |
| payload: { |
| file: document.getElementById('filePicker'), |
| }, |
| |
| |
| onProgress: function(event) { console.log('file uploading:', event) } |
| }); |
| |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| |
| |
| 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]; |
| |
| fileCopy = file.slice(); |
| } |
| |
| if (typeof file === 'undefined') { |
| console.warn('file 是 undefined,请检查代码或浏览器兼容性!'); |
| return; |
| } |
| |
| |
| let message = chat.createFileMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| payload: { |
| file: file |
| }, |
| onProgress: function(event) { console.log('file uploading:', event) } |
| }); |
| |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| }); |
| |
| |
| 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) } |
| }); |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| } |
| }); |
| |
| |
| |
| |
| 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) } |
| }); |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| } |
| }); |
| |
| import DocumentPicker from 'react-native-document-picker'; |
| |
| |
| DocumentPicker.pick({ |
| type: [DocumentPicker.types.allFiles], |
| }).then((result) => { |
| const file = result[0]; |
| |
| let message = chat.createFileMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| payload: { file: file }, |
| |
| |
| }); |
| |
| 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
| |
| |
| let message = chat.createLocationMessage({ |
| to: 'user1', |
| conversationType: TencentCloudChat.TYPES.CONV_C2C, |
| |
| |
| |
| payload: { |
| description: '深圳市深南大道10000号腾讯大厦', |
| longitude: 113.941079, |
| latitude: 22.546103 |
| } |
| }); |
| |
| 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
经度(最多保留到小数点后 6 位,精度为 0.1 米)
|
latitude |
Number
|
required
纬度(最多保留到小数点后 6 位,精度为 0.1 米)
|
|
cloudCustomData |
String
|
''
|
消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
|
priority |
String
|
TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL
|
消息优先级
|
|
Returns:
-
Type
-
Message
createMergerMessage(options) → {Message}
创建合并消息的接口,此接口返回一个消息实例,可以在需要发送合并消息时调用 发送消息 接口发送消息。
注意1:不支持合并已发送失败的消息,如果消息列表内传入了已发送失败的消息,则创建消息接口会报错。
Example
| |
| |
| 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或更高版本查看此消息' |
| }, |
| |
| |
| }); |
| |
| |
| 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 |
Array.<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
| |
| if (message.type === TencentCloudChat.TYPES.MSG_MERGER && message.payload.downloadKey !== '') { |
| let promise = chat.downloadMergerMessage(message); |
| promise.then(function(imResponse) { |
| |
| 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, |
| |
| |
| |
| payload: message, |
| |
| |
| }); |
| |
| 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。
接收端集成 uni-app 腾讯云推送服务(Push)或 react- native 腾讯云推送服务(Push)时,发送端 offlinePushInfo 中的功能,各个厂商支持情况:
厂商 |
自定义铃音 |
小图标 |
通知图片 |
长文本 |
华为 |
支持 |
支持 |
支持 |
支持 |
荣耀 |
- |
默认使用应用图标 |
支持 |
支持 |
OPPO |
支持 |
默认使用应用图标 |
- |
支持 |
vivo |
- |
默认使用应用图标 |
- |
title:40字符,description:108字符 (中文字符计算为2,英文字符计算为1) |
小米 |
支持 |
默认使用应用图标 |
- |
title:50字符,description:128字符 (中英文字符均计算为1) |
魅族 |
- |
默认使用应用图标 |
- |
title:32字符,description:100字符 (中文字符计算为2,英文字符计算为1) |
FCM |
支持 |
支持 |
支持 |
支持 |
apns |
支持 |
- |
支持 |
- |
效果示例:
Examples
| |
| |
| |
| chat.sendMessage(message); |
| |
| chat.sendMessage(message, { |
| onlineUserOnly: true |
| }); |
| |
| chat.sendMessage(message, { |
| offlinePushInfo: { |
| disablePush: true |
| } |
| }); |
| |
| chat.sendMessage(message, { |
| |
| offlinePushInfo: { |
| title: '', |
| description: '', |
| |
| androidInfo: { |
| OPPOChannelID: '' |
| } |
| } |
| }); |
| |
| chat.sendMessage(message, { |
| messageControlInfo: { |
| excludedFromUnreadCount: true, |
| excludedFromLastMessage: true |
| } |
| }); |
| |
| chat.sendMessage(message, { |
| messageControlInfo: { |
| excludedFromUnreadCount: true, |
| } |
| }); |
| |
| chat.sendMessage(message, { |
| messageControlInfo: { |
| excludedFromUnreadCount: true, |
| } |
| }); |
| |
| chat.sendMessage(message, { |
| offlinePushInfo: { |
| disablePush: false, |
| disableVoipPush: false |
| } |
| }); |
| |
| |
| |
| chat.sendMessage(message, { |
| messageControlInfo: { |
| excludedFromContentModeration: true, |
| } |
| }); |
| |
| chat.sendMessage(message, { |
| offlinePushInfo: { |
| androidInfo: { |
| sound: '' |
| } |
| } |
| }); |
| |
| chat.sendMessage(message, { |
| offlinePushInfo: { |
| androidInfo: { |
| HuaWeiImage: '' |
| } |
| } |
| }); |
| let message = chat.createTextMessage({ |
| to: 'test', |
| conversationType: TencentCloudChat.TYPES.CONV_GROUP, |
| payload: { |
| text: 'Hello world!' |
| } |
| }); |
| |
| let promise = chat.sendMessage(message, { webhookInfo: { |
| disableCloudMessagePreHook: true, |
| disableCloudMessagePostHook: true |
| }}); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
Parameters:
Name |
Type |
Description |
message |
Message
|
required
消息实例
|
options |
Object
|
消息发送选项
Properties
Name |
Type |
Default |
Description |
onlineUserOnly |
Boolean
|
false
|
消息是否仅发送给在线用户的标识,默认值为 false;设置为 true,则消息既不存漫游,也不会计入未读,也不会离线推送给接收方。适合用于发送广播通知等不重要的提示消息场景。在 AVChatRoom 发送消息不支持此选项。
|
offlinePushInfo |
Object
|
|
离线推送配置
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 "MyUniApp/nativeResources/android/res/raw/shake.xxx" 音频文件.
- 对应 react-native "MyReactNativeApp/android/app/src/main/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
|
华为手机用来标识消息类型。
|
OPPOCategory |
String
|
OPPO 手机用来标识消息类型,v3.4.9 起支持。
|
HuaWeiImage |
String
|
华为推送通知栏通知图片 url,v3.4.1 起支持。
- 使用的协议必须是 HTTPS 协议,取值样例:https://example.com/image.png
- 图片文件须小于 512KB,规格建议为 40dp x 40dp,弧角大小为 8dp。超出建议规格的图片会存在图片压缩或图片显示不全的情况。图片格式建议使用 JPG/JPEG/PNG。
|
HonorImage |
String
|
荣耀推送通知栏通知图片 url,v3.4.1 起支持。
- 使用的协议必须是 HTTPS 协议,取值样例:https://example.com/image.png
- 图标文件大小须小于 100KB,图标建议规格大小:160px x 160px,弧角大小为 32px,超出规格大小的图标会存在图片压缩或显示不全的情况。
|
GoogleImage |
String
|
Google 推送通知栏通知图片 url,v3.4.1 起支持。
- 使用的协议必须是 HTTPS 协议,取值样例:https://example.com/image.png
- 图标文件大小须小于 1 MB,超出规格大小的图标会存在图片压缩或显示不全的情况。
|
HonorImportance |
String
|
荣耀推送消息分类,v3.5.1起支持。
- "LOW": 表示消息为资讯营销类,默认展示方式为静默通知,仅在下拉通知栏展示。
- "NORMAL": 表示消息为服务通讯类,默认展示方式为锁屏展示 + 下拉通知栏展示。
|
|
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 "MyUniApp/nativeResources/ios/Resources/shake.xxx" 文件,uniapp 必须为正式包。
- 对应 react-native "MyReactNativeApp/ios/MyReactNativeApp/Resources/shake.xxx" 文件。
- 对应原生 Xcode 工程中的 "shake.xxx" 音频文件。
|
ignoreIOSBadge |
Boolean
|
离线推送忽略 badge 计数(仅对 iOS 生效),默认为 false,设置为 true 时,在 iOS 接收端,这条消息不会使 APP 的应用图标未读计数增加。
|
disableVoipPush |
Boolean
|
true 关闭 voip 推送(默认);false 开启 voip 推送(开启 voip 推送需要同时开启离线推送)
|
image |
String
|
标识 APNs 通知栏通知图片地址,当客户端拿到该字段时,可以通过下载图片资源的方式将图片展示在弹窗上,v3.4.1 起支持。
- 使用的协议必须是 HTTPS 协议,取值样例:https://example.com/image.png
- 支持 JPEG、GIF、PNG,大小不超过 10 MB
- 需要在 IM 控制台打开 mutable-content 属性,支持 iOS 10 Service Extension 特性
- 资源的 key 值是 "image"
|
|
|
messageControlInfo |
Object
|
|
消息控制信息。
Properties
Name |
Type |
Default |
Description |
excludedFromUnreadCount |
Boolean
|
false
|
true 消息不更新会话 unreadCount(消息存漫游)
|
excludedFromLastMessage |
Boolean
|
false
|
true 消息不更新会话 lastMessage(消息存漫游)
|
excludedFromContentModeration |
Boolean
|
false
|
消息是否不过内容审核(云端审核)
- 只有在开通【云端审核】功能后,excludedFromContentModeration 设置才有效,设置为 true,消息不过内容审核,设置为 false 消息过内容审核。
- 【云端审核】开通流程请参考 云端审核功能
|
|
webhookInfo |
Object
|
|
云端回调信息,v3.5.1 起支持。
Properties
Name |
Type |
Default |
Description |
disableCloudMessagePreHook |
Boolean
|
false
|
true 禁用消息发送前云端回调
|
disableCloudMessagePostHook |
Boolean
|
false
|
true 禁用消息发送后云端回调
|
|
|
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) { |
| |
| |
| }); |
| |
| 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, |
| excludedFromLastMessage: true |
| } |
| }); |
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}
Examples
| |
| let promise = chat.translateText({ |
| sourceTextList: ['مرحبًا'], |
| sourceLanguage: 'auto', |
| targetLanguage: 'en' |
| }); |
| promise.then(function(imResponse) { |
| |
| const { translatedTextList } = imResponse.data; |
| }).catch(function(imError) { |
| |
| 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) { |
| |
| const { translatedTextList } = imResponse.data; |
| }).catch(function(imError) { |
| |
| 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起支持。
Examples
| |
| 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:社群和话题支持消息扩展。
Examples
| |
| let message = chat.createTextMessage({ |
| to: 'test', |
| conversationType: TencentCloudChat.TYPES.CONV_GROUP, |
| payload: { |
| text: 'Hello world!' |
| }, |
| |
| isSupportExtension: true |
| }); |
| |
| let promise = chat.sendMessage(message); |
| promise.then(function(imResponse) { |
| |
| console.log(imResponse); |
| }).catch(function(imError) { |
| |
| console.warn('sendMessage error:', imError); |
| }); |
| 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) { |
| |
| } |
| }); |
| }).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; |
| |
| |
| }); |
| }).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
| |
| 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) { |
| |
| } |
| }); |
| }).catch(function(imError) { |
| |
| console.warn('deleteMessageExtensions error:', imError); |
| }); |
| |
| 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, '[TUIEmoji_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, '[TUIEmoji_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; |
| |
| |
| |
| |
| |
| }); |
| }).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: '[TUIEmoji_Smile]', |
| nextSeq: 0, |
| count: 100, |
| }); |
| promise.then(function(imResponse) { |
| |
| const { userList, nextSeq, isCompleted } = imResponse.data; |
| |
| |
| |
| }).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
| |
| let onMessageModified = function(event) { |
| |
| }; |
| chat.on(TencentCloudChat.EVENT.MESSAGE_MODIFIED, onMessageModified); |
| |
| |
| txtMessage.payload.text = "Hello Tencent"; |
| |
| let promise = chat.modifyMessage(txtMessage); |
| promise.then(function(imResponse) { |
| const { message } = imResponse.data; |
| |
| }).catch(function(imError) { |
| |
| const { code, data } = imError; |
| if (code === 2480) { |
| |
| } 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
| |
| 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; |
| }); |
| |
| 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; |
| }); |
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:业务侧调用该接口时,如果传 sequence 或 time,务必传入大于 0 的有效值,单次请求 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
| |
| let promise = chat.getMessageListHopping({conversationID: 'GROUPtest', sequence: xxx, count: 15, direction: 0}); |
| promise.then(function(imResponse) { |
| const { messageList, isCompleted, nextMessageSeq } = imResponse.data; |
| |
| |
| |
| }); |
| |
| let promise = chat.getMessageListHopping({conversationID: 'C2Ctest', time: xxx, count: 15, direction: 0}); |
| promise.then(function(imResponse) { |
| const { messageList, isCompleted, nextMessageTime } = imResponse.data; |
| |
| |
| |
| }); |
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) { |
| |
| }); |
| }); |
| |
| let messageList = null; |
| chat.getMessageList({conversationID: 'C2Ctest'}).then(function(imResponse) { |
| messageList = imResponse.data.messageList; |
| chat.sendMessageReadReceipt(messageList).then(function() { |
| |
| }).catch(function(imError) { |
| |
| }); |
| }); |
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; |
| |
| |
| |
| }).catch(function(imError) { |
| |
| }); |
| }); |
| |
| let messageList = null; |
| chat.getMessageList({conversationID: 'C2Ctest'}).then(function(imResponse) { |
| messageList = imResponse.data.messageList; |
| chat.getMessageReadReceiptList(messageList).then(function(imResponse) { |
| messageList = imResponse.data.messageList; |
| |
| |
| }).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; |
| |
| |
| |
| |
| }).catch(function(imError) { |
| |
| }); |
| |
| let promise = chat.getGroupMessageReadMemberList({ |
| message, |
| filter: 1, |
| cursor: '', |
| count: 30, |
| }); |
| promise.then(function(imResponse) { |
| const { isCompleted, cursor, messageID, unreadUserIDList } = imResponse.data; |
| |
| |
| |
| |
| }).catch(function(imError) { |
| |
| |
| }); |
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}
Example
| let message = chat.findMessage('144115217363870632-1647417469-77069006'); |
| if (message) { |
| |
| } |
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) { |
| |
| }).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; |
| }); |
| |
| 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; |
| }); |
| |
| let promise = chat.getConversationList({ groupName: '' }); |
| promise.then(function(imResponse) { |
| const conversationList = imResponse.data.conversationList; |
| }); |
| |
| let promise = chat.getConversationList({ hasUnreadCount: true }); |
| promise.then(function(imResponse) { |
| const conversationList = imResponse.data.conversationList; |
| }); |
| |
| 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; |
| }).catch(function(imError) { |
| console.warn('deleteConversation error:', imError); |
| }); |
| |
| let promise = chat.deleteConversation({conversationIDList: ['C2CExample'], clearHistoryMessage: false}); |
| promise.then(function(imResponse) { |
| |
| const { conversationIDList } = imResponse.data; |
| }).catch(function(imError) { |
| console.warn('deleteConversation error:', imError); |
| }); |
| |
| let promise = chat.deleteConversation({conversationIDList: ['C2CExample', 'GROUPExample']}); |
| promise.then(function(imResponse) { |
| |
| const { conversationIDList } = imResponse.data; |
| }).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; |
| }).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) { |
| |
| }).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}
Examples
| |
| let promise = chat.pinConversation({ conversationID: 'C2CExample', isPinned: true }); |
| promise.then(function(imResponse) { |
| |
| const { conversationID } = imResponse.data; |
| }).catch(function(imError) { |
| console.warn('pinConversation error:', imError); |
| }); |
| |
| let promise = chat.pinConversation({ conversationID: 'C2CExample', isPinned: false }); |
| promise.then(function(imResponse) { |
| |
| const { conversationID } = imResponse.data; |
| }).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(); |
| promise.then(function(imResponse) { |
| |
| }).catch(function(imError) { |
| |
| console.warn('setAllMessageRead error:', imError); |
| }); |
| |
| let promise = chat.setAllMessageRead({scope: TencentCloudChat.TYPES.READ_ALL_C2C_MSG}); |
| promise.then(function(imResponse) { |
| |
| }).catch(function(imError) { |
| |
| console.warn('setAllMessageRead error:', imError); |
| }); |
| |
| let promise = chat.setAllMessageRead({scope: TencentCloudChat.TYPES.READ_ALL_GROUP_MSG}); |
| promise.then(function(imResponse) { |
| |
| }).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 起支持群 @消息 提示类型。
注意7:v3.4.2 起支持用户在线时可设置仅接收话题 @消息,设置成功后,IM 后台会定期(默认10s)通知一次最新消息,SDK 通过 话题资料更新事件 将话题未读数和 lastMessage 通知给业务侧。
Examples
| |
| let promise = chat.setMessageRemindType({ groupID: 'group1', messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_DISCARD }); |
| promise.then(function(imResponse) { |
| |
| }).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) { |
| |
| }).catch(function(imError) { |
| console.warn('setMessageRemindType error:', imError); |
| }); |
| |
| let promise = chat.setMessageRemindType({ userIDList: ['user1', 'user2'], messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE }); |
| promise.then(function(imResponse) { |
| |
| const { successUserIDList, failureUserIDList } = imResponse.data; |
| |
| successUserIDList.forEach((item) => { |
| const { userID } = item; |
| }); |
| |
| 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); |
| }); |
| |
| let promise = chat.setMessageRemindType({ groupID: 'topicID', messageRemindType: TencentCloudChat.TYPES.NOT_RECEIVE_MSG_EXCEPT_AT }); |
| 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.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT(在线接收消息,离线仅接收群 @消息 的推送)
- TencentCloudChat.TYPES.NOT_RECEIVE_MSG_EXCEPT_AT(SDK 仅接收话题 @消息 并通知接入侧(抛出 收到消息事件),v3.4.2 起支持)
|
|
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
| |
| 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); |
| }); |
| |
| 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); |
| }); |
| |
| 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; |
| |
| |
| |
| |
| }).catch(function(imError) { |
| |
| console.warn('getAllReceiveMessageOpt error:', imError); |
| }); |
Returns:
-
Type
-
Promise
getTotalUnreadMessageCount() → {Number}
Example
| |
| let totalUnreadCount = chat.getTotalUnreadMessageCount(); |
Returns:
-
Type
-
Number
setConversationCustomData(options) → {Promise}
Examples
| |
| let promise = chat.setConversationCustomData({ |
| conversationIDList: ['GROUPtest', 'C2Cexample'], |
| customData: 'your custom data' |
| }); |
| promise.then(function(imResponse) { |
| |
| const { successConversationIDList, failureConversationIDList } = imResponse.data; |
| |
| |
| const conversationList = chat.getConversationList(successConversationIDList); |
| |
| |
| failureConversationIDList.forEach((item) => { |
| const { conversationID, code, message } = item; |
| }); |
| }).catch(function(imError) { |
| console.warn('setConversationCustomData error:', imError); |
| }); |
| |
| let promise = chat.setConversationCustomData({ |
| conversationIDList: ['GROUPtest', 'C2Cexample'], |
| customData: '' |
| }); |
| promise.then(function(imResponse) { |
| |
| const { successConversationIDList, failureConversationIDList } = imResponse.data; |
| |
| |
| const conversationList = chat.getConversationList(successConversationIDList); |
| |
| |
| 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; |
| |
| |
| const conversationList = chat.getConversationList(successConversationIDList); |
| |
| |
| 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; |
| }); |
| |
| 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}
Example
| let promise = chat.createConversationGroup({ |
| conversationIDList: ['GROUPtest', 'C2Cexample'], |
| groupName: 'Suppliers', |
| }); |
| promise.then(function(imResponse) { |
| |
| const { successConversationIDList, failureConversationIDList } = imResponse.data; |
| |
| |
| const conversationList = chat.getConversationList(successConversationIDList); |
| |
| |
| 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}
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}
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}
Example
| let promise = chat.addConversationsToGroup({ |
| conversationIDList: ['GROUPtest', 'C2Cexample'], |
| groupName: 'Suppliers_new', |
| }); |
| promise.then(function(imResponse) { |
| |
| const { successConversationIDList, failureConversationIDList } = imResponse.data; |
| |
| |
| const conversationList = chat.getConversationList(successConversationIDList); |
| |
| |
| 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}
Example
| let promise = chat.deleteConversationsFromGroup({ |
| conversationIDList: ['GROUPtest', 'C2Cexample'],, |
| groupName: 'Suppliers_new', |
| }); |
| promise.then(function(imResponse) { |
| |
| const { successConversationIDList, failureConversationIDList } = imResponse.data; |
| |
| |
| const conversationList = chat.getConversationList(successConversationIDList); |
| |
| |
| 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
searchCloudMessages(options) → {Promise}
搜索云端消息,v3.1 起支持。
注意1:此功能属于增值服务,需要您购买云端搜索插件,请点击 购买。
注意2:此接口云端限频 2次/秒, 本地接口调用默认限制 20次/5秒。
注意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', |
| }); |
| |
| |
| 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], |
| }); |
| |
| |
| 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); |
| for (let i = 0; i < searchResultList.length; i++) { |
| const searchResultItem = searchResultList[i]; |
| const { conversationID, messageCount, messageList } = searchResultItem; |
| console.log(conversationID); |
| console.log(messageCount); |
| |
| |
| |
| console.log(messageList); |
| } |
| }).catch(function(imError) { |
| console.error(imError); |
| }); |
| |
| |
| let promise = chat.searchCloudMessages({ |
| keywordList: ['你好', '在哪里'], |
| conversationID: 'GROUPPublic001' |
| }); |
| |
| |
| let promise = chat.searchCloudMessages({ |
| conversationID: 'GROUPPublic001', |
| messageTypeList: [TencentCloudChat.TYPES.MSG_IMAGE], |
| }); |
| |
| |
| let promise = chat.searchCloudMessages({ |
| keywordList: ['你好', '在哪里'], |
| conversationID: 'GROUPPublic001' |
| messageTypeList: [TencentCloudChat.TYPES.MSG_TEXT, TencentCloudChat.TYPES.MSG_CUSTOM], |
| }); |
| |
| |
| 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); |
| 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
searchCloudUsers(options) → {Promise}
搜索云端用户,v3.5.0 起支持。
搜索范围:根据关键词对所有用户的昵称(nick) 进行模糊搜索匹配, 对所有用户的 userID 进行精准搜索匹配。
注意1:此功能属于增值服务,需要您购买云端搜索插件,请点击 购买。
注意2:获取的用户列表中的资料是不完整的(仅包括头像 avatar、昵称 nick、用户账号 userID、性别 gender、生日 birthday、个性签名 selfSignature 等,能够满足用户搜索结果列表的渲染需求,不包含自定义字段),若要查询详细用户资料,可参考:getUserProfile。
注意3:云端限频 2次/秒, 本地接口调用默认限制 20次/5秒。
注意4:单次最大搜索数结果量为 100 条。
Examples
| |
| |
| let promise = chat.searchCloudUsers({ |
| keywordList: ['test', 'user'], |
| }); |
| |
| |
| let promise = chat.searchCloudUsers({ |
| keywordList: ['test', 'user'], |
| keywordListMatchType: 'and', |
| }); |
| |
| |
| let promise = chat.searchCloudUsers({ |
| keywordList: ['test', 'user'], |
| gender: TencentCloudChat.TYPES.GENDER.FEMALE, |
| }); |
| |
| |
| |
| let promise = chat.searchCloudUsers({ |
| keywordList: ['test', 'user'], |
| miniBirthday: 19500101, |
| maxBirthday: 20240101, |
| }); |
| |
| |
| let promise = chat.searchCloudUsers({ |
| keywordList: ['test', 'user'], |
| miniBirthday: 19500101, |
| }); |
| |
| |
| let promise = chat.searchCloudUsers({ |
| keywordList: ['test', 'user'], |
| maxBirthday: 20240101, |
| }); |
| |
| promise.then(function(imResponse) { |
| |
| const { totalCount, cursor, searchResultList } = imResponse.data; |
| console.log(totalCount); |
| console.log(cursor); |
| console.log(searchResultList); |
| for (let i = 0; i < searchResultList.length; i++) { |
| const profileItem = searchResultList[i]; |
| const { userID, nick, gender, avatar } = profileItem; |
| console.log(userID); |
| console.log(nick); |
| console.log(gender); |
| console.log(avatar); |
| } |
| }).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: “与”关系搜索
|
gender |
String
|
用户性别,不传入时默认搜索所有性别用户。性别表示:
- TencentCloudChat.TYPES.GENDER_FEMALE 女性
- TencentCloudChat.TYPES.GENDER_MALE 男性
|
miniBirthday |
Number
|
用户最小生日,如 19900101
|
maxBirthday |
Number
|
用户最大生日,与 miniBirthday 同时设置时则必须大于等于 miniBirthday,如 20240101
|
cursor |
String
|
每次云端搜索的起始位置。第一次搜索时不要传入 cursor,继续搜索时填入上次调用 searchCloudUsers 接口返回的 cursor 的值
|
count |
Number
|
每次云端搜索结果的数量,默认值为 20, 最大值为100。
|
|
Returns:
-
Type
-
Promise
searchCloudGroups(options) → {Promise}
搜索云端群列表,v3.5.0 起支持。
搜索范围:根据关键词对所有群的群名称 (name) 进行模糊匹配搜索, 对所有群组的 groupID 进行精准搜索匹配。
注意1:此功能属于增值服务,需要您购买云端搜索插件,请点击 购买。
注意2:该接口获取的群列表中的资料是不完整的(仅包括群组ID groupID、群组头像 avatar、群组名称 name、群组类型 type、群组人数 memberCount、群组简介 introduction、群主 ownerID 等,能够满足群搜索结果列表的渲染需求),若要查询详细群资料,可参考:getGroupProfile。
注意3:云端限频 2次/秒, 本地接口调用默认限制 20次/5秒。
注意4:不支持直播群(TencentCloudChat.TYPES.GRP_AVCHATROOM)类型的搜索。
注意5:单次最大搜索数结果量为 100。
Examples
| |
| |
| let promise = chat.searchCloudGroups({ |
| keywordList: ['test', 'user'], |
| }); |
| |
| |
| let promise = chat.searchCloudGroups({ |
| keywordList: ['test', 'user'], |
| keywordListMatchType: 'and', |
| }); |
| |
| |
| let promise = chat.searchCloudGroups({ |
| keywordList: ['test', 'user'], |
| groupTypeList: [TencentCloudChat.TYPES.GRP_PUBLIC, TencentCloudChat.TYPES.GRP_WORK], |
| }); |
| |
| promise.then(function(imResponse) { |
| |
| const { totalCount, cursor, searchResultList } = imResponse.data; |
| console.log(totalCount); |
| console.log(cursor); |
| console.log(searchResultList); |
| for (let i = 0; i < searchResultList.length; i++) { |
| const groupItem = searchResultList[i]; |
| const { groupID, name, type, avatar, memberCount, introduction, ownerID } = groupItem; |
| console.log(groupID); |
| console.log(name); |
| console.log(type); |
| console.log(avatar); |
| console.log(memberCount); |
| console.log(introduction); |
| console.log(ownerID); |
| } |
| }).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: “与”关系搜索
|
groupTypeList |
Array.<String>
|
不传入时默认搜索所有类型群组(不支持直播群(TencentCloudChat.TYPES.GRP_AVCHATROOM)类型的搜索)。群类型表示:
- TencentCloudChat.TYPES.GRP_WORK 好友工作群
- TencentCloudChat.TYPES.GRP_PUBLIC 陌生人社交群
- TencentCloudChat.TYPES.GRP_MEETING 临时会议群
- TencentCloudChat.TYPES.GRP_COMMUNITY 社群
|
cursor |
String
|
每次云端搜索的起始位置。第一次搜索时不要传入 cursor,继续搜索时填入上次调用 searchCloudGroups 接口返回的 cursor 的值
|
count |
Number
|
每次云端搜索结果的数量,默认值为 20, 最大值为100。
|
|
Returns:
-
Type
-
Promise
searchCloudGroupMembers(options) → {Promise}
搜索云端群成员列表,v3.5.0 起支持。
搜索范围:在当前登录用户所在的所有群组的群成员中,根据关键词对群成员用户昵称(nick)、群名片(nameCard) 进行关键字模糊匹配搜索, 对群成员 userID 进行精确匹配搜索。
注意1:此功能属于增值服务,需要您购买云端搜索插件,请点击 购买。
注意2:该接口获取的群成员列表中的资料是不完整的,搜索结果按照 群 groupID 进行分组。
注意3:搜索结果中仅包括群部分资料(群组ID groupID、群组名称 name、群组类型 type、群组头像 avatar)与部分群成员部分资料(群成员ID userID、群成员昵称 nick、群名片 nameCard),能够满足群成员搜索结果列表的渲染需求),若要查询详细群成员资料,可参考:getGroupMemberProfile。
注意3:云端限频 2次/秒, 本地接口调用默认限制 20次/5秒。
注意4:不支持直播群(TencentCloudChat.TYPES.GRP_AVCHATROOM)类型的搜索。
注意5:单次最大搜索数结果量为 100 条。
Examples
| |
| |
| let promise = chat.searchCloudGroupMembers({ |
| keywordList: ['test', 'user'], |
| }); |
| |
| |
| let promise = chat.searchCloudGroupMembers({ |
| keywordList: ['test', 'user'], |
| keywordListMatchType: 'and', |
| }); |
| |
| |
| let promise = chat.searchCloudGroupMembers({ |
| keywordList: ['test', 'user'], |
| groupTypeList: [TencentCloudChat.TYPES.GRP_PUBLIC, TencentCloudChat.TYPES.GRP_WORK], |
| }); |
| |
| |
| let promise = chat.searchCloudGroupMembers({ |
| keywordList: ['test', 'user'], |
| groupIDList: ['group1', 'group2'], |
| }); |
| |
| promise.then(function(imResponse) { |
| |
| const { totalCount, cursor, searchResultList } = imResponse.data; |
| console.log(totalCount); |
| console.log(cursor); |
| console.log(searchResultList); |
| for (let i = 0; i < searchResultList.length; i++) { |
| const searchResultItem = searchResultList[i]; |
| const { groupInfo, memberList } = searchResultItem; |
| const { groupID, name, type, avatar } = groupInfo; |
| |
| console.log(groupID, name, type, avatar); |
| console.log(memberList); |
| for (let i = 0; i < memberList.length; i++) { |
| const memberItem = memberList[i]; |
| const { userID, nick, nameCard } = memberItem; |
| console.log(userID); |
| console.log(nick); |
| console.log(nameCard); |
| } |
| } |
| }).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: “与”关系搜索
|
groupTypeList |
Array.<String>
|
搜索的群组类型列表,不传入时默认搜索所有类型群组(不支持直播群(TencentCloudChat.TYPES.GRP_AVCHATROOM)类型的搜索)。群类型表示:
- TencentCloudChat.TYPES.GRP_WORK 好友工作群
- TencentCloudChat.TYPES.GRP_PUBLIC 陌生人社交群
- TencentCloudChat.TYPES.GRP_MEETING 临时会议群
- TencentCloudChat.TYPES.GRP_COMMUNITY 社群
|
groupIDList |
Array.<String>
|
搜索指定群 ID 列表,不传入时默认搜索所有群组
|
cursor |
String
|
每次云端搜索的起始位置。第一次搜索时不要传入 cursor,继续搜索时填入上次调用 searchCloudGroups 接口返回的 cursor 的值
|
count |
Number
|
每次云端搜索结果的数量,默认值为 20, 最大值为100。
|
|
Returns:
-
Type
-
Promise
getMyProfile() → {Promise}
- See:
-
Example
| let promise = chat.getMyProfile(); |
| promise.then(function(imResponse) { |
| console.log(imResponse.data); |
| }).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'] |
| }); |
| promise.then(function(imResponse) { |
| console.log(imResponse.data); |
| }).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); |
| }); |
| |
| |
| let promise = chat.updateMyProfile({ |
| |
| |
| 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: '我的昵称', |
| |
| 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); |
| }).catch(function(imError) { |
| console.warn('getBlacklist error:', imError); |
| }); |
Returns:
-
Type
-
Promise
addToBlacklist(options) → {Promise}
添加用户到黑名单列表。将用户加入黑名单后可以屏蔽来自 TA 的所有消息,因此该接口可以实现“屏蔽该用户消息”的功能。
默认情况下,将好友加入黑名单后,会解除双方的好友关系(类似 QQ 的处理方式)
- 如果用户 A 与用户 B 之间存在好友关系,拉黑时会解除双向好友关系。
- 如果用户 A 与用户 B 之间存在黑名单关系,二者之间无法发起会话。
- 如果用户 A 与用户 B 之间存在黑名单关系,二者之间无法发起加好友请求。
注意1:您可以在即时通信 IM 控制台,找到相应 SDKAppID,单击消息服务 Chat > 功能配置 > 登录与消息 > 黑名单检查,配置发送消息后是否展示发送成功。
启用此配置项,用户拉黑他人,拉黑后不再收到来自对方的单聊消息;被拉黑用户侧发消息后仍展示发送成功 (实际对方不会收到消息) 。停用此设置项,则被拉黑用户侧发消息后会提示失败,SDK会收到错误码20007。
注意2:黑名单列表上限1000,且不可调整。
注意3:如果您需要将好友加入黑名单后仍保留好友关系,请到 即时通信 IM 控制台,找到相应 SDKAppID,单击消息服务 Chat > 功能配置 > 好友与关系链 > 拉黑配置,选择【保留好友关系】。
Example
| let promise = chat.addToBlacklist({userIDList: ['user1', 'user2']}); |
| promise.then(function(imResponse) { |
| console.log(imResponse.data); |
| }).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']}); |
| promise.then(function(imResponse) { |
| console.log(imResponse.data); |
| }).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}
Example
| |
| let promise = chat.setSelfStatus({customStatus: 'xxx'}); |
| promise.then(function(imResponse) { |
| console.log(imResponse.data); |
| const { userID, statusType, customStatus } = imResponse.data; |
| |
| |
| |
| |
| |
| |
| |
| }).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
| |
| |
| let promise = chat.getUserStatus({userIDList: [`${myUserID}`]}); |
| promise.then(function(imResponse) { |
| const { successUserList } = imResponse.data; |
| successUserList.forEach((item) => { |
| const { userID, statusType, customStatus } = item; |
| |
| |
| |
| |
| |
| |
| |
| }); |
| }).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; |
| |
| |
| |
| |
| |
| |
| |
| }); |
| |
| |
| failureUserList.forEach((item) => { |
| const { userID, code, message } = item; |
| |
| |
| |
| }); |
| }).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}
Example
| let promise = chat.subscribeUserStatus({userIDList: ['user0', 'user1']}); |
| promise.then(function(imResponse) { |
| const { failureUserList } = imResponse.data; |
| |
| failureUserList.forEach((item) => { |
| const { userID, code, message } = item; |
| |
| |
| |
| }); |
| }).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}
Examples
| |
| let promise = chat.unsubscribeUserStatus({userIDList: ['user0', 'user1']}); |
| promise.then(function(imResponse) { |
| const { failureUserList } = imResponse.data; |
| |
| failureUserList.forEach((item) => { |
| const { userID, code, message } = item; |
| |
| |
| |
| }); |
| }).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; |
| |
| |
| |
| }); |
| }).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}
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) { |
| |
| } else if (code === 0) { |
| |
| } |
| }).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
|
''
|
加好友附言:
|
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
|
''
|
好友备注
|
groupName |
String
|
''
|
分组信息
|
|
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; |
| |
| successUserIDList.forEach((item) => { |
| const { userID } = item; |
| }); |
| |
| failureUserIDList.forEach((item) => { |
| const { userID, code, message } = item; |
| }); |
| |
| }).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; |
| |
| successUserIDList.forEach((item) => { |
| const { userID, code, relation } = item; |
| |
| |
| |
| |
| |
| |
| |
| |
| }); |
| |
| 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) => { |
| |
| }); |
| |
| 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}
Examples
| |
| let promise = chat.updateFriend({ |
| userID: 'user1', |
| remark: 'helloworld' |
| }); |
| promise.then(function(imResponse) { |
| console.log(imResponse.data); |
| }).catch(function(imError) { |
| console.warn('getFriendProfile error:', imError); |
| }); |
| |
| let promise = chat.updateFriend({ |
| userID: 'user1', |
| friendCustomField: [ |
| |
| { key: 'Tag_SNS_Custom_test1', value: 'hello' }, |
| { key: 'Tag_SNS_Custom_test2', value: 'world' }, |
| ] |
| }); |
| promise.then(function(imResponse) { |
| console.log(imResponse.data); |
| }).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
|
''
|
好友备注
|
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}
Example
| let promise = chat.getFriendApplicationList(); |
| promise.then(function(imResponse) { |
| |
| |
| |
| |
| }); |
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) { |
| |
| }).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) { |
| |
| }).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) { |
| |
| }).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}
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; |
| |
| |
| |
| }).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); |
| |
| }).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; |
| |
| |
| |
| }).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; |
| |
| |
| |
| }).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); |
| |
| }).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; |
| |
| |
| 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; |
| |
| |
| 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; |
| |
| |
| 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) => { |
| |
| |
| }); |
| }).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' |
| }] |
| }); |
| promise.then(function(imResponse) { |
| console.log(imResponse.data.group); |
| |
| |
| |
| 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); |
| }); |
| |
| 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); |
| }).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.', |
| |
| 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, |
| }); |
| 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); |
| }).catch(function(imError){ |
| console.warn('quitGroup error:', imError); |
| }); |
Parameters:
Name |
Type |
Description |
groupID |
String
|
required
群组 ID
|
Returns:
-
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) => { |
| |
| |
| |
| |
| |
| |
| |
| |
| 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}
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}
Examples
| |
| let promise = chat.deleteGroupAttributes({ |
| groupID: 'group1', |
| keyList: ['key1', 'key2'] |
| }); |
| promise.then(function(imResponse) { |
| console.log(imResponse.data.keyList); |
| }).catch(function(imError) { |
| console.warn('deleteGroupAttributes error:', imError); |
| }); |
| |
| let promise = chat.deleteGroupAttributes({ |
| groupID: 'group1', |
| keyList: [] |
| }); |
| promise.then(function(imResponse) { |
| console.log(imResponse.data.keyList); |
| }).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); |
| }).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}
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}
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
| |
| let promise = chat.getGroupMemberList({ groupID: 'group1', role: TencentCloudChat.TYPES.GRP_MBR_ROLE_ADMIN, count: 15, offset: 0 }); |
| 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 }); |
| 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 }); |
| 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 }); |
| 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 }); |
| 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'], |
| memberCustomFieldFilter: ['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:
-
Type
-
Promise
addGroupMember(options) → {Promise}
添加群成员。详细规则如下:
- TencentCloudChat.TYPES.GRP_WORK(好友工作群):默认任何群成员都可以直接邀请他人进群,且无需被邀请人同意,直接将其拉入群组中。可将 inviteOption 设置为 TencentCloudChat.TYPES.INVITE_OPTIONS_DISABLE_INVITE 禁止任何群成员邀请他人进群。
- TencentCloudChat.TYPES.GRP_PUBLIC(陌生人社交群)/ TencentCloudChat.TYPES.GRP_MEETING(临时会议群):默认不支持群成员邀请他人进群,可通过设置 inviteOption 控制邀请进群选项。
- TencentCloudChat.TYPES.GRP_COMMUNITY(社群):默认支持群成员邀请他人进群。
- 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); |
| console.log(imResponse.data.failureUserIDList); |
| console.log(imResponse.data.existedUserIDList); |
| |
| |
| console.log(imResponse.data.overLimitUserIDList); |
| console.log(imResponse.data.group); |
| }).catch(function(imError) { |
| console.warn('addGroupMember error:', imError); |
| }); |
| |
| 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) { |
| |
| } |
| }); |
| }) |
| |
| 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); |
| console.log(imResponse.data.failureUserIDList); |
| console.log(imResponse.data.existedUserIDList); |
| |
| |
| 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
| |
| let promise = chat.deleteGroupMember({groupID: 'group1', userIDList:['user1'], reason: '你违规了,我要踢你!'}); |
| promise.then(function(imResponse) { |
| console.log(imResponse.data.group); |
| console.log(imResponse.data.userIDList); |
| }).catch(function(imError) { |
| console.warn('deleteGroupMember error:', imError); |
| }); |
| |
| 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); |
| }).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 |
| }); |
| 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 |
| }); |
| 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 |
| }); |
| 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; |
| |
| |
| }).catch(function(imError) { |
| console.warn('markGroupMemberList error:', imError); |
| }); |
| |
| let promise = chat.getGroupMemberList({ groupID: 'group1', filter: 1000, offset: 0 }); |
| 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
获取支持话题的社群列表。
注意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
创建话题。
注意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); |
| }).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); |
| }).catch(function(imError) { |
| console.warn('createTopicInCommunity error:', imError); |
| }); |
| |
| let message = chat.createTextMessage({ |
| to: '@TGS#_@TGS#cWWFWHIM62CL@TOPIC#_@TOPIC#cXWFWHIM62CR', |
| 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
删除话题。
注意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.dismissGroup('group1'); |
| promise.then(function(imResponse) { |
| console.log(imResponse.data.groupID); |
| }).catch(function(imError) { |
| console.warn('dismissGroup 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}
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
|
话题名称
|
avatar |
String
|
话题头像
|
notification |
String
|
话题公告
|
introduction |
String
|
话题简介
|
customData |
String
|
话题自定义信息
|
muteAllMembers |
Boolean
|
设置全体禁言,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); |
| }); |
| |
| let message = chat.createTextMessage({ |
| to: '@TGS#_@TGS#cWWFWHIM62CL@TOPIC#_@TOPIC#cXWFWHIM62CR', |
| 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; |
| |
| |
| }).catch(function(imError) { |
| console.warn('getTopicListSync error:', imError); |
| }) |
| } |
| } |
| |
| 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); |
| }); |
| |
| let promise = chat.invite({ |
| userID: 'user1', |
| data: JSON.stringify({ excludeFromHistoryMessage: true }), |
| }); |
| promise.then(function(imResponse) { |
| console.warn('invite success:', imResponse) |
| }).catch(function(imError) { |
| console.warn('invite error:', imError); |
| }); |
| |
| let promise = chat.invite({ |
| userID: 'user1', |
| data: '', |
| timeout: 30 |
| }); |
| promise.then(function(imResponse) { |
| console.warn('invite success:', imResponse) |
| }).catch(function(imError) { |
| console.warn('invite error:', imError); |
| }); |
| |
| let promise = chat.invite({ |
| userID: 'user1', |
| data: '', |
| timeout: 30, |
| onlineUserOnly: true |
| }); |
| promise.then(function(imResponse) { |
| console.warn('invite success:', imResponse) |
| }).catch(function(imError) { |
| console.warn('invite error:', imError); |
| }); |
| |
| let promise = chat.invite({ |
| userID: 'user1', |
| data: '', |
| timeout: 30, |
| offlinePushInfo: { |
| disablePush: false, |
| disableVoipPush: false, |
| title: '', |
| description: '', |
| androidInfo: { |
| androidOPPOChannelID: '' |
| } |
| } |
| }); |
| 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
|
离线推送透传内容
|
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 "MyUniApp/nativeResources/android/res/raw/shake.xxx" 音频文件.
- 对应 react-native "MyReactNativeApp/android/app/src/main/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
|
华为手机用来标识消息类型。
|
OPPOCategory |
String
|
OPPO 手机用来标识消息类型,v3.4.9 起支持。
|
HuaWeiImage |
String
|
华为推送通知栏通知图片 url,v3.4.1 起支持。
- 使用的协议必须是 HTTPS 协议,取值样例:https://example.com/image.png
- 图片文件须小于 512KB,规格建议为 40dp x 40dp,弧角大小为 8dp。超出建议规格的图片会存在图片压缩或图片显示不全的情况。图片格式建议使用 JPG/JPEG/PNG。
|
HonorImage |
String
|
荣耀推送通知栏通知图片 url,v3.4.1 起支持。
- 使用的协议必须是 HTTPS 协议,取值样例:https://example.com/image.png
- 图标文件大小须小于 100KB,图标建议规格大小:160px x 160px,弧角大小为 32px,超出规格大小的图标会存在图片压缩或显示不全的情况。
|
GoogleImage |
String
|
Google 推送通知栏通知图片 url,v3.4.1 起支持。
- 使用的协议必须是 HTTPS 协议,取值样例:https://example.com/image.png
- 图标文件大小须小于 1 MB,超出规格大小的图标会存在图片压缩或显示不全的情况。
|
HonorImportance |
String
|
荣耀推送消息分类,v3.5.1起支持。
- "LOW": 表示消息为资讯营销类,默认展示方式为静默通知,仅在下拉通知栏展示。
- "NORMAL": 表示消息为服务通讯类,默认展示方式为锁屏展示 + 下拉通知栏展示。
|
|
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 "MyUniApp/nativeResources/ios/Resources/shake.xxx" 文件,uniapp 必须为正式包。
- 对应 react-native "MyReactNativeApp/ios/MyReactNativeApp/Resources/shake.xxx" 文件。
- 对应原生 Xcode 工程中的 "shake.xxx" 音频文件。
|
ignoreIOSBadge |
Boolean
|
离线推送忽略 badge 计数(仅对 iOS 生效),默认为 false,设置为 true 时,在 iOS 接收端,这条消息不会使 APP 的应用图标未读计数增加。
|
disableVoipPush |
Boolean
|
true 关闭 voip 推送(默认);false 开启 voip 推送(开启 voip 推送需要同时开启离线推送)
|
image |
String
|
标识 APNs 通知栏通知图片地址,当客户端拿到该字段时,可以通过下载图片资源的方式将图片展示在弹窗上,v3.4.1 起支持。
- 使用的协议必须是 HTTPS 协议,取值样例:https://example.com/image.png
- 支持 JPEG、GIF、PNG,大小不超过 10 MB
- 需要在 IM 控制台打开 mutable-content 属性,支持 iOS 10 Service Extension 特性
- 资源的 key 值是 "image"
|
|
|
|
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); |
| }); |
| |
| let promise = chat.inviteInGroup({ |
| groupID: 'AV1', |
| inviteeList: ['user1', 'user2'], |
| data: JSON.stringify({ excludeFromHistoryMessage: true }), |
| }); |
| promise.then(function(imResponse) { |
| console.warn('inviteInGroup success:', imResponse) |
| }).catch(function(imError) { |
| console.warn('inviteInGroup error:', imError); |
| }); |
| |
| 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); |
| }); |
| |
| let promise = chat.inviteInGroup({ |
| groupID: 'AV1', |
| inviteeList: ['user1', 'user2'], |
| data: '', |
| timeout: 30, |
| onlineUserOnly: true |
| }); |
| promise.then(function(imResponse) { |
| console.warn('inviteInGroup success:', imResponse) |
| }).catch(function(imError) { |
| console.warn('inviteInGroup error:', imError); |
| }); |
| |
| let promise = chat.inviteInGroup({ |
| groupID: 'AV1', |
| inviteeList: ['user1', 'user2'], |
| data: '', |
| timeout: 30, |
| offlinePushInfo: { |
| disablePush: false, |
| disableVoipPush: false, |
| title: '', |
| description: '', |
| androidInfo: { |
| androidOPPOChannelID: '' |
| } |
| } |
| }); |
| 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
|
离线推送透传内容
|
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 "MyUniApp/nativeResources/android/res/raw/shake.xxx" 音频文件.
- 对应 react-native "MyReactNativeApp/android/app/src/main/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
|
华为手机用来标识消息类型。
|
OPPOCategory |
String
|
OPPO 手机用来标识消息类型,v3.4.9 起支持。
|
HuaWeiImage |
String
|
华为推送通知栏通知图片 url,v3.4.1 起支持。
- 使用的协议必须是 HTTPS 协议,取值样例:https://example.com/image.png
- 图片文件须小于 512KB,规格建议为 40dp x 40dp,弧角大小为 8dp。超出建议规格的图片会存在图片压缩或图片显示不全的情况。图片格式建议使用 JPG/JPEG/PNG。
|
HonorImage |
String
|
荣耀推送通知栏通知图片 url,v3.4.1 起支持。
- 使用的协议必须是 HTTPS 协议,取值样例:https://example.com/image.png
- 图标文件大小须小于 100KB,图标建议规格大小:160px x 160px,弧角大小为 32px,超出规格大小的图标会存在图片压缩或显示不全的情况。
|
GoogleImage |
String
|
Google 推送通知栏通知图片 url,v3.4.1 起支持。
- 使用的协议必须是 HTTPS 协议,取值样例:https://example.com/image.png
- 图标文件大小须小于 1 MB,超出规格大小的图标会存在图片压缩或显示不全的情况。
|
HonorImportance |
String
|
荣耀推送消息分类,v3.5.1起支持。
- "LOW": 表示消息为资讯营销类,默认展示方式为静默通知,仅在下拉通知栏展示。
- "NORMAL": 表示消息为服务通讯类,默认展示方式为锁屏展示 + 下拉通知栏展示。
|
|
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 "MyUniApp/nativeResources/ios/Resources/shake.xxx" 文件,uniapp 必须为正式包。
- 对应 react-native "MyReactNativeApp/ios/MyReactNativeApp/Resources/shake.xxx" 文件。
- 对应原生 Xcode 工程中的 "shake.xxx" 音频文件。
|
ignoreIOSBadge |
Boolean
|
离线推送忽略 badge 计数(仅对 iOS 生效),默认为 false,设置为 true 时,在 iOS 接收端,这条消息不会使 APP 的应用图标未读计数增加。
|
disableVoipPush |
Boolean
|
true 关闭 voip 推送(默认);false 开启 voip 推送(开启 voip 推送需要同时开启离线推送)
|
image |
String
|
标识 APNs 通知栏通知图片地址,当客户端拿到该字段时,可以通过下载图片资源的方式将图片展示在弹窗上,v3.4.1 起支持。
- 使用的协议必须是 HTTPS 协议,取值样例:https://example.com/image.png
- 支持 JPEG、GIF、PNG,大小不超过 10 MB
- 需要在 IM 控制台打开 mutable-content 属性,支持 iOS 10 Service Extension 特性
- 资源的 key 值是 "image"
|
|
|
|
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); |
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