### Download TUIKit Component (Windows) Source: https://github.com/tencentcloud/chat-uikit-wechat/blob/main/README.md Install the TUIKit component using npm and copy it to your project's TUIKit directory using xcopy. ```shell npm i @tencentcloud/chat-uikit-wechat xcopy node_modules\@tencentcloud\chat-uikit-wechat .\TUIKit /i /e ``` -------------------------------- ### Download TUIKit Component (macOS) Source: https://github.com/tencentcloud/chat-uikit-wechat/blob/main/README.md Install the TUIKit component using npm and copy it to your project's TUIKit directory. ```shell npm i @tencentcloud/chat-uikit-wechat cp -r node_modules/@tencentcloud/chat-uikit-wechat/ ./TUIKit ``` -------------------------------- ### Check and Initiate TUICallKit Calls Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Checks if TUICallKit is integrated and demonstrates how to initiate one-on-one or group audio/video calls. Ensure TUICallKit is installed before calling these methods. ```javascript // 检查是否已集成 TUICallKit import TUICore, { TUIConstants } from '@tencentcloud/tui-core'; const hasCallKit = TUICore.getService(TUIConstants.TUICalling.SERVICE.NAME); if (hasCallKit) { // 发起单人通话 TUICore.callService({ serviceName: TUIConstants.TUICalling.SERVICE.NAME, method: TUIConstants.TUICalling.SERVICE.METHOD.START_CALL, params: { userIDList: ['user002'], type: 1, // 1-语音通话, 2-视频通话 }, }); // 发起群组通话 TUICore.callService({ serviceName: TUIConstants.TUICalling.SERVICE.NAME, method: TUIConstants.TUICalling.SERVICE.METHOD.START_CALL, params: { groupID: 'group001', userIDList: ['user002', 'user003'], type: 2, // 视频通话 }, }); } else { wx.showToast({ title: '请先集成 TUICallKit 组件', icon: 'none', }); } ``` -------------------------------- ### Configure WeChat Mini Program Subpackages Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Demonstrates how to configure subpackages in `app.json` to manage the main package size for complex WeChat Mini Program projects. This example shows how to include the TUI-CustomerService module as a subpackage. ```json // app.json - 配置分包 { "pages": [ "pages/index/index" ], "subPackages": [ { "root": "TUI-CustomerService", "name": "TUI-CustomerService", "pages": [ "pages/index" ], "independent": false } ], "window": { "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "IM Demo", "navigationBarTextStyle": "black" } } ``` -------------------------------- ### Initialize npm Project Source: https://github.com/tencentcloud/chat-uikit-wechat/blob/main/README.md Before downloading TUIKit components, create a package.json file in your WeChat mini-program project using npm init. ```shell npm init ``` -------------------------------- ### Navigate to Subpackage Page from Main Package Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Shows how to navigate from a page in the main package to a page within a subpackage using `wx.navigateTo`. Ensure the subpackage is correctly configured in `app.json`. ```javascript // 主包页面跳转到分包 Page({ handleJump() { wx.navigateTo({ url: '../../TUI-CustomerService/pages/index', }); } }); ``` -------------------------------- ### Initialize Chat SDK in app.js Source: https://github.com/tencentcloud/chat-uikit-wechat/blob/main/README.md Configure and initialize the TencentCloud Chat SDK globally in the app.js file. ```javascript import TencentCloudChat from '@tencentcloud/chat'; import TIMUploadPlugin from 'tim-upload-plugin'; import TIMProfanityFilterPlugin from 'tim-profanity-filter-plugin'; import { genTestUserSig } from './debug/GenerateTestUserSig'; App({ onLaunch: function () { wx.$TUIKit = TencentCloudChat.create({ SDKAppID: this.globalData.config.SDKAPPID, }); const userSig = genTestUserSig(this.globalData.config).userSig wx.$chat_SDKAppID = this.globalData.config.SDKAPPID; wx.TencentCloudChat = TencentCloudChat; wx.$chat_userID = this.globalData.config.userID; wx.$chat_userSig = userSig; wx.$TUIKit.registerPlugin({ 'tim-upload-plugin': TIMUploadPlugin }); wx.$TUIKit.registerPlugin({ 'tim-profanity-filter-plugin': TIMProfanityFilterPlugin }); wx.$TUIKit.login({ userID: this.globalData.config.userID, userSig }); // 监听系统级事件 wx.$TUIKit.on(wx.TencentCloudChat.EVENT.SDK_READY, this.onSDKReady,this); }, onUnload() { wx.$TUIKit.off(wx.TencentCloudChat.EVENT.SDK_READY, this.onSDKReady,this); }, globalData: { config: { userID: '', // User ID SECRETKEY: '', // Your secretKey SDKAPPID: 0, // Your SDKAppID EXPIRETIME: 604800, }, }, onSDKReady(event) { // 监听到此事件后可调用 SDK 发送消息等 API,使用 SDK 的各项功能。 } }); ``` -------------------------------- ### 发送视频消息 Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt 通过选择视频文件并调用 createVideoMessage 接口进行发送,支持上传进度监听。 ```javascript // 选择视频 wx.chooseMedia({ count: 1, sourceType: ['album', 'camera'], mediaType: ['video'], maxDuration: 60, success: (res) => { const file = res.tempFiles[0]; // 创建视频消息 const message = wx.$TUIKit.createVideoMessage({ to: 'user002', conversationType: wx.TencentCloudChat.TYPES.CONV_C2C, payload: { file: { type: 'video', tempFiles: [{ tempFilePath: file.tempFilePath }] }, }, onProgress: (percent) => { console.log('视频上传进度:', Math.floor(percent * 100) + '%'); }, }); // 发送视频消息 wx.$TUIKit.sendMessage(message).then((res) => { console.log('视频发送成功'); }).catch((error) => { console.error('视频发送失败:', error); }); } }); ``` -------------------------------- ### Initialize TUIKit in App Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Initialize the TUIKit instance and register necessary plugins within the WeChat App lifecycle. ```javascript // app.js - 在小程序 App 中初始化 TUIKit import TencentCloudChat from '@tencentcloud/chat'; import TIMUploadPlugin from 'tim-upload-plugin'; import TIMProfanityFilterPlugin from 'tim-profanity-filter-plugin'; import { genTestUserSig } from './debug/GenerateTestUserSig'; App({ onLaunch: function () { // 创建 TUIKit 实例 wx.$TUIKit = TencentCloudChat.create({ SDKAppID: this.globalData.config.SDKAPPID, }); // 生成用户签名 const userSig = genTestUserSig(this.globalData.config).userSig; // 存储全局配置 wx.$chat_SDKAppID = this.globalData.config.SDKAPPID; wx.$chat_userID = this.globalData.config.userID; wx.$chat_userSig = userSig; wx.TencentCloudChat = TencentCloudChat; // 注册插件 wx.$TUIKit.registerPlugin({ 'tim-upload-plugin': TIMUploadPlugin }); wx.$TUIKit.registerPlugin({ 'tim-profanity-filter-plugin': TIMProfanityFilterPlugin }); // 用户登录 wx.$TUIKit.login({ userID: this.globalData.config.userID, userSig }); // 监听 SDK 就绪事件 wx.$TUIKit.on(wx.TencentCloudChat.EVENT.SDK_READY, this.onSDKReady, this); }, globalData: { config: { userID: 'your_user_id', // 用户ID SECRETKEY: 'your_secret_key', // 密钥(仅用于测试) SDKAPPID: 0, // 应用ID EXPIRETIME: 604800, // 签名过期时间(秒) }, }, onSDKReady(event) { console.log('SDK 已就绪,可以使用 IM 功能'); } }); ``` -------------------------------- ### TUIKit Component Initialization in JS Source: https://github.com/tencentcloud/chat-uikit-wechat/blob/main/README.md Initialize the TUIKit component in your page's JS file. This involves importing necessary modules, creating the chat instance, registering plugins, and logging in. The SDK readiness event is handled to further initialize the TUIKit component. ```javascript import TencentCloudChat from '@tencentcloud/chat'; import TIMUploadPlugin from 'tim-upload-plugin'; import TIMProfanityFilterPlugin from 'tim-profanity-filter-plugin'; import { genTestUserSig } from '../../TUIKit/debug/GenerateTestUserSig'; Page({ data: { config: { userID: '', //User ID SDKAPPID: 0, // Your SDKAppID SECRETKEY: '', // Your secretKey EXPIRETIME: 604800, } }, onLoad() { const userSig = genTestUserSig(this.data.config).userSig wx.$TUIKit = TencentCloudChat.create({ SDKAppID: this.data.config.SDKAPPID }) wx.$chat_SDKAppID = this.data.config.SDKAPPID; wx.$chat_userID = this.data.config.userID; wx.$chat_userSig = userSig; wx.TencentCloudChat = TencentCloudChat; wx.$TUIKit.registerPlugin({ 'tim-upload-plugin': TIMUploadPlugin }); wx.$TUIKit.registerPlugin({ 'tim-profanity-filter-plugin': TIMProfanityFilterPlugin }); wx.$TUIKit.login({ userID: this.data.config.userID, userSig }); wx.setStorage({ key: 'currentUserID', data: [], }); wx.$TUIKit.on(wx.TencentCloudChat.EVENT.SDK_READY, this.onSDKReady,this); }, onUnload() { wx.$TUIKit.off(wx.TencentCloudChat.EVENT.SDK_READY, this.onSDKReady,this); }, onSDKReady() { const TUIKit = this.selectComponent('#TUIKit'); TUIKit.init(); } }); ``` -------------------------------- ### 发送文本消息 Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt 创建文本消息并发送,支持通过 cloudCustomData 携带自定义扩展数据。 ```javascript // 创建文本消息 const message = wx.$TUIKit.createTextMessage({ to: 'user002', // 接收方ID conversationType: wx.TencentCloudChat.TYPES.CONV_C2C, // 单聊: CONV_C2C, 群聊: CONV_GROUP payload: { text: '你好,这是一条测试消息!' }, cloudCustomData: JSON.stringify({ messageFeature: { needTyping: 1, version: 1, }, }), }); // 发送消息 wx.$TUIKit.sendMessage(message, { offlinePushInfo: { disablePush: false, title: '新消息', description: '你收到一条新消息', } }).then((res) => { console.log('消息发送成功:', res.data.message); }).catch((error) => { console.error('消息发送失败:', error.code, error.message); // 常见错误码: // 80001 - 包含违禁词汇 // 20007 - 已被对方拉黑 // 10007 - 不是群成员 }); ``` -------------------------------- ### Configure Component in JSON Source: https://github.com/tencentcloud/chat-uikit-wechat/blob/main/README.md Register the TUIKit component in the subpackage's page configuration file. ```json { "usingComponents": { "TUIKit": "../TUIKit/index" }, "navigationStyle": "custom" } ``` -------------------------------- ### 发送图片消息 Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt 使用微信小程序 API 选择图片后,通过 create the image message 接口创建并发送。 ```javascript // 选择图片 wx.chooseMedia({ count: 9, sourceType: ['album'], // 'album' 或 'camera' mediaType: ['image'], success: (res) => { const tempFiles = res.tempFiles; tempFiles.forEach(file => { // 创建图片消息 const message = wx.$TUIKit.createImageMessage({ to: 'user002', conversationType: wx.TencentCloudChat.TYPES.CONV_C2C, payload: { file: { type: 'image', tempFiles: [{ tempFilePath: file.tempFilePath }] }, }, onProgress: (percent) => { console.log('上传进度:', Math.floor(percent * 100) + '%'); }, }); // 发送图片消息 wx.$TUIKit.sendMessage(message).then((res) => { console.log('图片发送成功'); }).catch((error) => { console.error('图片发送失败:', error); }); }); } }); ``` -------------------------------- ### Trigger Subpackage Navigation Source: https://github.com/tencentcloud/chat-uikit-wechat/blob/main/README.md Implement navigation to the subpackage from the main package. ```html 载入腾讯云 IM 分包 ``` ```javascript Page({ handleJump() { wx.navigateTo({ url: '../../TUI-CustomerService/pages/index', }) } }) ``` -------------------------------- ### Reference TUIKit Component in Page Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Configure the TUIKit component within a page's WXML, JS, and JSON files to enable chat interfaces. ```html ``` ```javascript // index.js import TencentCloudChat from '@tencentcloud/chat'; import TIMUploadPlugin from 'tim-upload-plugin'; import { genTestUserSig } from '../../TUIKit/debug/GenerateTestUserSig'; Page({ data: { config: { userID: 'user001', SDKAPPID: 1400000000, SECRETKEY: 'your_secret_key', EXPIRETIME: 604800, } }, onLoad() { const userSig = genTestUserSig(this.data.config).userSig; wx.$TUIKit = TencentCloudChat.create({ SDKAppID: this.data.config.SDKAPPID }); wx.$chat_SDKAppID = this.data.config.SDKAPPID; wx.$chat_userID = this.data.config.userID; wx.$chat_userSig = userSig; wx.TencentCloudChat = TencentCloudChat; wx.$TUIKit.registerPlugin({ 'tim-upload-plugin': TIMUploadPlugin }); wx.$TUIKit.login({ userID: this.data.config.userID, userSig }); wx.$TUIKit.on(wx.TencentCloudChat.EVENT.SDK_READY, this.onSDKReady, this); }, onSDKReady() { const TUIKit = this.selectComponent('#TUIKit'); TUIKit.init(); } }); ``` ```json // index.json { "usingComponents": { "TUIKit": "../../TUIKit/index" }, "navigationStyle": "custom" } ``` -------------------------------- ### 发送语音消息 Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt 利用 RecorderManager 录制音频,并在停止录音后创建并发送语音消息。 ```javascript // 初始化录音管理器 const recorderManager = wx.getRecorderManager(); // 开始录音 recorderManager.start({ duration: 60000, // 最长录音时长 60秒 sampleRate: 44100, // 采样率 numberOfChannels: 1, // 录音通道数 encodeBitRate: 192000, // 编码码率 format: 'aac', // 音频格式 (aac 支持全平台互通) }); // 停止录音并发送 recorderManager.onStop((res) => { if (res.duration < 1000) { wx.showToast({ title: '录音时间太短', icon: 'none' }); return; } // 创建语音消息 const message = wx.$TUIKit.createAudioMessage({ to: 'user002', conversationType: wx.TencentCloudChat.TYPES.CONV_C2C, payload: { file: res, // 录音文件信息 }, }); // 发送语音消息 wx.$TUIKit.sendMessage(message).then((res) => { console.log('语音消息发送成功'); }).catch((error) => { console.error('语音消息发送失败:', error); }); }); // 停止录音 recorderManager.stop(); ``` -------------------------------- ### Initialize TUIKit in JS Source: https://github.com/tencentcloud/chat-uikit-wechat/blob/main/README.md Initialize the TUIKit component within the page's onLoad lifecycle method. ```javascript Page({ // 其他代码 onLoad() { const TUIKit = this.selectComponent('#TUIKit'); TUIKit.init(); }, }); ``` -------------------------------- ### Group Creation and Joining Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Endpoints to create new groups or request to join existing ones. ```APIDOC ## Group Creation and Joining ### Description Create new group chats or apply to join existing public groups. ### Methods - **createGroup**: Create a new group with specified type and members. - **joinGroup**: Request to join a group with an optional application message. ``` -------------------------------- ### Register Subpackage in app.json Source: https://github.com/tencentcloud/chat-uikit-wechat/blob/main/README.md Define the subpackage structure within the main app.json file to enable modular loading. ```json { "pages": [ "pages/index/index" ], "subPackages": [ { "root": "TUI-CustomerService", "name": "TUI-CustomerService", "pages": [ "pages/index" ], "independent": false } ], "window": { "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "Weixin", "navigationBarTextStyle": "black" }, "style": "v2", "sitemapLocation": "sitemap.json" } ``` -------------------------------- ### Generate Test UserSig for IM Authentication Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Provides a client-side method for generating test UserSigs, essential for IM user authentication. For production environments, UserSig must be generated on the server. Ensure the SECRETKEY is not exposed in client code. ```javascript // debug/GenerateTestUserSig.js import LibGenerateTestUserSig from './lib-generate-test-usersig-es.min.js'; function genTestUserSig(config) { const { SDKAPPID, SECRETKEY, EXPIRETIME, userID } = config; const generator = new LibGenerateTestUserSig(SDKAPPID, SECRETKEY, EXPIRETIME); const userSig = generator.genTestUserSig(userID); return { sdkAppID: SDKAPPID, userSig, }; } // 使用示例 const config = { userID: 'user001', SDKAPPID: 1400000000, SECRETKEY: 'your_secret_key', EXPIRETIME: 604800, // 7天 }; const { sdkAppID, userSig } = genTestUserSig(config); console.log('UserSig:', userSig); // 注意: // 1. 仅用于开发测试,正式环境必须在服务端生成 UserSig // 2. SECRETKEY 不能暴露在客户端代码中 // 3. 服务端生成方式请参考: https://cloud.tencent.com/document/product/269/32688 ``` -------------------------------- ### TUIKit Component Configuration in JSON Source: https://github.com/tencentcloud/chat-uikit-wechat/blob/main/README.md Declare the TUIKit component in your page's JSON file to make it available for use. This also sets the navigation style to custom. ```json { "usingComponents": { "TUIKit": "../../TUIKit/index" }, "navigationStyle": "custom" } ``` -------------------------------- ### 管理会话与消息监听 Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt 获取会话详情、设置已读状态、分页获取历史消息,并监听新消息、已读回执及撤回事件。 ```javascript // 获取会话详情 wx.$TUIKit.getConversationProfile('C2Cuser002').then((res) => { const conversation = res.data.conversation; console.log('会话名称:', conversation.remark || conversation.userProfile.nick); console.log('会话类型:', conversation.type); }); // 设置消息已读 wx.$TUIKit.setMessageRead({ conversationID: 'C2Cuser002' }).then(() => { console.log('消息已读设置成功'); }); // 获取历史消息列表 wx.$TUIKit.getMessageList({ conversationID: 'C2Cuser002', nextReqMessageID: '', // 用于分页,首次传空 count: 15 }).then((res) => { const messageList = res.data.messageList; const nextReqMessageID = res.data.nextReqMessageID; const isCompleted = res.data.isCompleted; messageList.forEach(msg => { console.log(`[${msg.flow}] ${msg.type}: `, msg.payload); }); }); // 监听新消息 wx.$TUIKit.on(wx.TencentCloudChat.EVENT.MESSAGE_RECEIVED, (event) => { const messageList = event.data; messageList.forEach(message => { console.log('收到新消息:', message); }); }); // 监听消息已读回执 wx.$TUIKit.on(wx.TencentCloudChat.EVENT.MESSAGE_READ_BY_PEER, (event) => { event.data.forEach(message => { console.log('消息已被对方阅读:', message.ID); }); }); // 监听消息撤回 wx.$TUIKit.on(wx.TencentCloudChat.EVENT.MESSAGE_REVOKED, (event) => { const revokedMessageID = event.data[0].ID; console.log('消息已撤回:', revokedMessageID); }); ``` -------------------------------- ### Embed TUIKit Component in WXML Source: https://github.com/tencentcloud/chat-uikit-wechat/blob/main/README.md Add the TUIKit component to the subpackage's WXML file. ```html ``` -------------------------------- ### Create and Join Groups with WeChat UIKit Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Create new groups of different types (Work, Public, Meeting, AVChatRoom) or join existing groups, with options for applying with a message and handling different join statuses. ```javascript // 创建群组 wx.$TUIKit.createGroup({ type: wx.TencentCloudChat.TYPES.GRP_WORK, // Work/Public/Meeting/AVChatRoom name: '技术讨论群', groupID: 'tech_group_001', // 可选,不填则自动生成 memberList: [ { userID: 'user002' }, { userID: 'user003' }, ], introduction: '这是一个技术交流群', notification: '欢迎加入技术讨论群!', }).then((imResponse) => { const group = imResponse.data.group; console.log('群组创建成功:', group.groupID); // 创建会话并进入聊天 const conversationID = `GROUP${group.groupID}`; // 跳转到聊天页面 }); // 加入群组 wx.$TUIKit.joinGroup({ groupID: 'public_group_001', applyMessage: '申请加入群组', }).then((imResponse) => { switch (imResponse.data.status) { case wx.TencentCloudChat.TYPES.JOIN_STATUS_WAIT_APPROVAL: console.log('等待管理员审批'); break; case wx.TencentCloudChat.TYPES.JOIN_STATUS_SUCCESS: console.log('加入群组成功'); break; case wx.TencentCloudChat.TYPES.JOIN_STATUS_ALREADY_IN_GROUP: console.log('已在群组中'); break; } }); ``` -------------------------------- ### TUIKit Component in WXML Source: https://github.com/tencentcloud/chat-uikit-wechat/blob/main/README.md Include the TUIKit component in your page's WXML file. The 'config' attribute is used to pass configuration options. ```html ``` -------------------------------- ### Manage TUIConversation List Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Retrieve conversation lists, listen for updates, and manage user online status subscriptions. ```javascript // 获取会话列表 wx.$TUIKit.getConversationList().then((imResponse) => { const conversationList = imResponse.data.conversationList; console.log('会话列表:', conversationList); // conversationList 包含每个会话的详细信息: // - conversationID: 会话ID // - type: 会话类型 (C2C/GROUP) // - unreadCount: 未读消息数 // - lastMessage: 最后一条消息 }); // 监听会话列表更新 wx.$TUIKit.on(wx.TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED, (event) => { const conversationList = event.data; console.log('会话列表已更新:', conversationList); }); // 订阅用户在线状态 const userIDList = ['user001', 'user002', 'user003']; wx.$TUIKit.getUserStatus({ userIDList }).then((imResponse) => { const { successUserList } = imResponse.data; successUserList.forEach(user => { console.log(`用户 ${user.userID} 状态: ${user.statusType}`); // statusType: 1-在线, 2-离线, 3-未登录 }); }); // 订阅在线状态变更通知 wx.$TUIKit.subscribeUserStatus({ userIDList }); wx.$TUIKit.on(wx.TencentCloudChat.EVENT.USER_STATUS_UPDATED, (event) => { event.data.forEach(user => { console.log(`用户 ${user.userID} 状态变更为: ${user.statusType}`); }); }); ``` -------------------------------- ### Group Management with TUIGroup Component Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Manage group functionalities using the TUIGroup component, including fetching group profiles and member lists, adding members, and handling group exits or dismissals. ```javascript // 获取群组资料 wx.$TUIKit.getGroupProfile({ groupID: 'group001', }).then((imResponse) => { const group = imResponse.data.group; console.log('群名称:', group.name); console.log('群成员数:', group.memberCount); console.log('群主:', group.ownerID); console.log('我的角色:', group.selfInfo.role); // Owner/Admin/Member }); // 获取群成员列表(分页) wx.$TUIKit.getGroupMemberList({ groupID: 'group001', count: 30, offset: 0, }).then((imResponse) => { const memberList = imResponse.data.memberList; memberList.forEach(member => { console.log(`成员: ${member.nick || member.userID}, 角色: ${member.role}`); }); }); // 添加群成员(仅 Work 群支持) wx.$TUIKit.addGroupMember({ groupID: 'group001', userIDList: ['user003', 'user004'], }).then((imResponse) => { const { successUserIDList, existedUserIDList, failureUserIDList } = imResponse.data; console.log('添加成功:', successUserIDList); console.log('已在群中:', existedUserIDList); console.log('添加失败:', failureUserIDList); }); // 退出群聊 wx.$TUIKit.quitGroup('group001').then(() => { console.log('退出群聊成功'); }).catch((imError) => { console.error('退出群聊失败:', imError); }); // 解散群聊(仅群主可操作) wx.$TUIKit.dismissGroup('group001').then(() => { console.log('群聊已解散'); }).catch((imError) => { console.error('解散群聊失败:', imError); }); ``` -------------------------------- ### Message Lifecycle Operations Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Provides methods to manage existing messages, including revoking, deleting, and resending failed messages. ```APIDOC ## Message Lifecycle Operations ### Description Manage message states. Revoke allows removing messages within a 2-minute window, delete removes them from the local list, and resend attempts to re-send failed messages. ### Methods - **revokeMessage**: Revoke a message. - **deleteMessage**: Delete a message. - **resendMessage**: Resend a failed message. ``` -------------------------------- ### Message Operations: Revoke, Delete, Resend Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Perform operations on sent messages, including revoking messages within 2 minutes, deleting messages, and resending failed messages. ```javascript // 撤回消息(2分钟内的消息) wx.$TUIKit.revokeMessage(message).then((imResponse) => { console.log('消息撤回成功'); // 更新消息列表,显示"已撤回"提示 }).catch((imError) => { if (imError.code === 20016) { wx.showToast({ title: '超过2分钟消息不支持撤回', icon: 'none' }); } }); // 删除消息 wx.$TUIKit.deleteMessage([message]).then((imResponse) => { console.log('消息删除成功'); // 从消息列表中移除该消息 }).catch((imError) => { console.error('消息删除失败:', imError); }); // 重发失败的消息 wx.$TUIKit.resendMessage(failedMessage).then((res) => { console.log('消息重发成功:', res.data.message); // 更新消息列表中的消息状态 }).catch((imError) => { console.error('消息重发失败:', imError.code); }); ``` -------------------------------- ### POST /messages/custom Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Sends a custom message, such as an order card or typing status, to a specific user or conversation. ```APIDOC ## POST /messages/custom ### Description Sends a custom message payload. This can be used for business-specific UI elements like order cards or system states like typing indicators. ### Method POST ### Request Body - **to** (string) - Required - The target user ID. - **conversationType** (number) - Required - The type of conversation (e.g., C2C). - **payload** (object) - Required - The custom data object containing businessID and content. ### Request Example { "to": "user002", "conversationType": 1, "payload": { "data": "{\"businessID\":\"order\",\"title\":\"商品订单\"}", "description": "订单消息" } } ``` -------------------------------- ### Group Management API Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Operations for managing group profiles, members, and group lifecycle. ```APIDOC ## Group Management API ### Description Provides functionality to retrieve group profiles, manage member lists, add members, quit groups, or dismiss groups. ### Methods - **getGroupProfile**: Retrieve details of a specific group. - **getGroupMemberList**: Fetch paginated list of group members. - **addGroupMember**: Add new members to a group. - **quitGroup**: Leave a group. - **dismissGroup**: Delete a group (Owner only). ``` -------------------------------- ### Send Custom Messages with WeChat UIKit Source: https://context7.com/tencentcloud/chat-uikit-wechat/llms.txt Use `createCustomMessage` to send various custom message types, such as order cards or typing indicators. The `onlineUserOnly` option can be used to send messages only to online users. ```javascript // 发送订单卡片消息 const orderPayload = { data: JSON.stringify({ businessID: 'order', title: '商品订单', description: 'iPhone 15 Pro Max 256GB', price: '9999.00', imageUrl: 'https://example.com/product.jpg', link: 'https://example.com/order/12345', }), description: '订单消息', extension: '', }; const orderMessage = wx.$TUIKit.createCustomMessage({ to: 'user002', conversationType: wx.TencentCloudChat.TYPES.CONV_C2C, payload: orderPayload, }); wx.$TUIKit.sendMessage(orderMessage).then((res) => { console.log('订单消息发送成功'); }); // 发送正在输入状态消息(仅在线用户可见) const typingMessage = wx.$TUIKit.createCustomMessage({ to: 'user002', conversationType: wx.TencentCloudChat.TYPES.CONV_C2C, payload: { data: JSON.stringify({ businessID: 'user_typing_status', typingStatus: 1, // 1-正在输入, 0-输入结束 version: 1, userAction: 14, actionParam: 'EIMAMSG_InputStatus_Ing', }), description: '', extension: '', }, }); // 仅发送给在线用户 wx.$TUIKit.sendMessage(typingMessage, { onlineUserOnly: true, }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.