
chat-example.
npm init -y
npm i @tencentcloud/chat-uikit-uniapp unplugin-vue2-script-setup
mkdir -p ./TUIKit && rsync -av --exclude={'node_modules','package.json','excluded-list.txt'} ./node_modules/@tencentcloud/chat-uikit-uniapp/ ./TUIKit
mkdir -p ./TUIKit/tui-customer-service-plugin && rsync -av ./node_modules/@tencentcloud/tui-customer-service-plugin/ ./TUIKit/tui-customer-service-plugin
npm i @tencentcloud/chat-uikit-uniapp unplugin-vue2-script-setup
xcopy .\\node_modules\\@tencentcloud\\chat-uikit-uniapp .\\TUIKit /i /e /exclude:.\\node_modules\\@tencentcloud\\chat-uikit-uniapp\\excluded-list.txt
xcopy .\\node_modules\\@tencentcloud\\tui-customer-service-plugin .\\TUIKit\\tui-customer-service-plugin /i /e
const ScriptSetup = require('unplugin-vue2-script-setup/webpack').default;module.exports = {parallel: false,configureWebpack: {plugins: [ScriptSetup({/* options */}),],},chainWebpack(config) {// disable type check and let `vue-tsc` handles itconfig.plugins.delete('fork-ts-checker');},};
manifest.json file{"mp-weixin": {"appid": "","optimization": {"subPackages": true}},"h5": {"optimization": {"treeShaking": {"enable": false}}}}
Vue.use(VueCompositionAPI) , to prevent inability to use environment variables such as isPC.// Introduce the main package dependencyimport TencentCloudChat from "@tencentcloud/chat";import TUICore from "@tencentcloud/tui-core";import App from './App';// #ifndef VUE3import Vue from 'vue';import './uni.promisify.adaptor';import VueCompositionAPI from "@vue/composition-api";Vue.use(VueCompositionAPI);Vue.config.productionTip = false;App.mpType = 'app';const app = new Vue({...App,});app.$mount();// #endif// #ifdef VUE3import { createSSRApp } from 'vue';export function createApp() {const app = createSSRApp(App);return {app,};}// #endif
{"pages": [{"path": "pages/index/index" // Your project's homepage}],"subPackages": [{"root": "TUIKit","pages": [{"path": "components/TUIChat/index","style": {"navigationBarTitleText": "Tencent Cloud IM"}},// To integrate the chat component, this path must be configured: video playback{"path": "components/TUIChat/video-play","style": {"navigationBarTitleText": "Tencent Cloud IM"}},{"path": "components/TUIChat/web-view","style": {"navigationBarTitleText": "Tencent Cloud IM"}},{"path": "components/TUIContact/index","style": {"navigationBarTitleText": "Tencent Cloud IM"}},{"path": "components/TUIGroup/index","style": {"navigationBarTitleText": "Tencent Cloud IM"}}]}],"preloadRule": {"TUIKit/components/TUIChat/index": {"network": "all","packages": ["TUIKit"]}},"globalStyle": {"navigationBarTextStyle": "black","navigationBarTitleText": "uni-app","navigationBarBackgroundColor": "#F8F8F8","backgroundColor": "#F8F8F8"}}
<script lang="ts">// #ifdef APP-PLUS || H5import { TUIChatKit, genTestUserSig } from "./TUIKit";import { vueVersion } from "./TUIKit/adapter-vue";import { TUILogin } from "@tencentcloud/tui-core";// #endif// Mandatory informationconst config = {userID: "test-user1", //User IDSDKAppID: 0, // Your SDKAppIDsecretKey: "", // Your secretKey};uni.$chat_userID = config.userID;uni.$chat_SDKAppID = config.SDKAppID;uni.$chat_secretKey = config.secretKey;// #ifdef APP-PLUS || H5uni.$chat_userSig = genTestUserSig(config).userSig;// Initialization of TUIChatKitTUIChatKit.init();// #endifexport default {onLaunch: function () {// #ifdef APP-PLUS || H5// TUICore loginTUILogin.login({SDKAppID: uni.$chat_SDKAppID,userID: uni.$chat_userID,// UserSig is the cipher for users to sign in to Instant Messaging, essentially being the ciphertext obtained from encrypting information such as UserID.// This method is only suitable for running the Demo locally and debugging functions. For more information, please refer to https://www.tencentcloud.com/document/product/269/32688?from_cn_redirect=1userSig: uni.$chat_userSig,// Should you require to send image, voice, video, file and other rich media messages, please set `Setting` to `true`useUploadPlugin: true,// Local review can successfully identify and handle inappropriate and unsafe content, thereby ensuring the safety and enhancing the user experience of your products// This functionality is a value-added service, please refer to: https://www.tencentcloud.com/document/product/269/79139?from_cn_redirect=1// If you have purchased the content review service, to activate this feature please set it to `true`useProfanityFilterPlugin: false,framework: `vue${vueVersion}` // Current development uses framework vue2 / vue3});// #endif},onShow: function() {console.log('App Show')},onHide: function() {console.log('App Hide')}};</script><style>/*Common CSS for each page*/uni-page-body,html,body,page {width: 100% !important;height: 100% !important;overflow: hidden;}</style>
TUIKit/components/TUIChat/index.vue:// #ifdef MP-WEIXINimport { TUIChatKit, genTestUserSig } from "../../index.ts";import { vueVersion, onMounted } from "../../adapter-vue";import { TUILogin } from "@tencentcloud/tui-core";import { onLoad } from '@dcloudio/uni-app';// #endif
// Initialization of TUIChatKit// Attention: Due to the compatibility issues of conditional compilation, the following conditional compilation code must be written below the const variable// #ifdef MP-WEIXINTUIChatKit.init();uni.$chat_userSig = genTestUserSig({userID: uni.$chat_userID,SDKAppID: uni.$chat_SDKAppID,secretKey: uni.$chat_secretKey}).userSig;onLoad((options) => {// loginTUILogin.login({SDKAppID: uni.$chat_SDKAppID,userID: uni.$chat_userID,// UserSig is the cipher for users to sign in to Instant Messaging, essentially being the ciphertext obtained from encrypting information such as UserID.// This method is only suitable for running Demo locally and debugging functions. For details, please refer to https://www.tencentcloud.com/document/product/269/32688?from_cn_redirect=1userSig: uni.$chat_userSig,// Should you require to send image, voice, video, file and other rich media messages, please set `Setting` to `true`useUploadPlugin: true,// Local review can successfully identify and handle inappropriate and unsafe content, thereby ensuring the safety and enhancing the user experience of your products// This functionality is a value-added service, please refer to: https://www.tencentcloud.com/document/product/269/79139?from_cn_redirect=1// If you have purchased the content review service, to activate this feature please set it to `true`useProfanityFilterPlugin: false,framework: `vue${vueVersion}` // Current development uses framework vue2 / vue3}).then(() => {uni.showToast({title: "login success"});const conversationID = options.conversationID;TUIConversationService.switchConversation(conversationID);});});// #endif

config object's SDKAppID, secretKey, and userID. The SDKAppID and secretKey can be accessed through the Instant Messaging console, while the userID can be obtained during account creation in the Instant Messaging console.// Mandatory informationconst config = {userID: "test-user1", // Login User IDSDKAppID: 0, // Your SDKAppIDsecretKey: "", // Your secretKey};
test-user1.
<template><div class="TUI-chat"><p class="TUI-chat-button" @click="openChat">Open 1v1 chat</p><p class="TUI-chat-button" @click="openGroupChat">Open Group Chat</p></div></template><script>import { TUIConversationService } from "@tencentcloud/chat-uikit-engine";export default {components: {},data() {return {userID: "test-user2", // Please input the opposite-end userID. Refer to Step 6groupID: "", // Accessible groupID by invoking API createGroup, for more details, refer to: https://web.sdk.qcloud.com/im/doc/chat-engine/ITUIGroupService.html#createGroup};},methods: {// Initiate a one-to-one chatopenChat() {// Switch conversation into chatconst conversationID = `C2C${this.userID}`;// #ifdef APP-PLUS || H5TUIConversationService.switchConversation(conversationID);// #endifuni.navigateTo({url: `/TUIKit/components/TUIChat/index?conversationID=${conversationID}`,});},// Open the group chatopenGroupChat() {const conversationID = `GROUP${this.groupID}`;// #ifdef APP-PLUS || H5TUIConversationService.switchConversation(conversationID);// #endifuni.navigateTo({url: `/TUIKit/components/TUIChat/index?conversationID=${conversationID}`,});},},};</script><style lang="scss" scoped>.TUI-chat {display: flex;flex-direction: column;align-items: center;height: 100%;&-button {width: 180px;padding: 10px 40px;background-color: #006eff;color: #fff;font-size: 16px;margin-top: 65px;border-radius: 30px;text-align: center;}}</style>


unpackage/dist/dev/mp-weixin under the project root directory using the WeChat Developer Tool.TUIConversationService.switchConversation() method in the onLoad event. This method proactively clears the current conversation's unread count, thus there is no need for manually deleting the unread count.フィードバック