
Security News
High Salaries No Longer Enough to Attract Top Cybersecurity Talent
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
@tencentcloud/ai-desk-customer-uniapp
Advanced tools
智能客服用户端 uni-app UIKit。使用此 UIKit,您可以在一天内将智能客服的能力集成到您的 Web、小程序、App 项目。极简接入,一套代码多端运行,且体验一致,用 AI 为您的产品增收提效。
HBuilderX 升级到最新版本
TypeScript / JavaScript (UIKit 使用 ts 语言开发,支持在 js 或者 ts 项目中集成)
Vue2 / Vue3
sass(sass-loader 版本 ≤ 10.1.1)
node(12.13.0 ≤ node 版本 ≤ 17.0.0, 推荐使用 Node.js 官方 LTS 版本 16.17.0)
npm(版本请与 node 版本匹配)
打开 HbuilderX,在菜单栏中选择 “文件-新建-项目”,创建一个名为 ai-desk-example
的 uni-app 项目。Vue 版本选择推荐 3。
HBuilderX 创建项目时默认不会创建 package.json
文件,请在项目根目录下执行以下命令创建 package.json
文件:
npm init -y
通过 NPM 方式下载 UIKit。
npm i @tencentcloud/ai-desk-customer-uniapp unplugin-vue2-script-setup
为了方便您对 UI 进行扩展,请在项目的根目录下执行以下命令,将 UIKit 源码复制到项目中。
【macOS 端】
mkdir -p ./ai-desk-customer-uniapp &&
rsync -av --exclude={'node_modules','package.json','excluded-list.txt','script'} ./node_modules/@tencentcloud/ai-desk-customer-uniapp/ ai-desk-customer-uniapp/
【Windows 端】
xcopy .\node_modules\@tencentcloud\ai-desk-customer-uniapp .\ai-desk-customer-uniapp /i /e /exclude:.\node_modules\@tencentcloud\ai-desk-customer-uniapp\excluded-list.txt
【manifest.json 文件】
在 manifest.json
文件的源码视图中开启小程序分包 subPackages
和关闭 H5 treeShaking
选项。
// weixin miniProgram
"mp-weixin" : {
"appid" : "",
"optimization" : {
"subPackages" : true
}
},
// H5: close treeshaking to solve the problem of uni[methond]() is not a function
"h5" : {
"optimization" : {
"treeShaking" : {
"enable" : false
}
}
},
注意:
小程序默认使用分包集成,打包小程序时
manifest.json
不要配置 lazyCodeLoading 选项。
【vue.config.js(Vue3 项目无需修改)】
Vue2 项目必须在根目录下创建或修改 vue.config.js 。
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 it
config.plugins.delete('fork-ts-checker');
},
};
为了规避小程序主包体积超限问题,我们建议您将客服 UIKit 放入分包。假设您的主包页面是 pages/index/index.vue
,分包页面是 pages-ai-desk/index/index.vue
,主包页面有一个咨询客服的入口,用户点击后跳转至分包的智能客服页面。项目的目录结构如下所示:
----YOUR-UNI-APP-PROJECT
----ai-desk-customer-uniapp
----pages
--------index
------------index.vue
----pages-ai-desk
--------index
------------index.vue
----App.vue
----manifest.json
----pages.json
请将以下内容复制到项目对应的文件中。
【App.vue 文件】
<script>
export default {
onLaunch: function() {
console.log('App Launch')
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
}
}
</script>
<style>
uni-page-body,
html,
body,
page {
width: 100% !important;
height: 100% !important;
overflow: hidden;
}
#app {
height: 100% !important;
}
</style>
【pages.json 文件】
{
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "uni-app"
}
}
],
"subPackages": [{
"root": "pages-ai-desk",
"pages": [{
"path": "index/index",
"style": {
"navigationBarTitleText": "智能客服",
"navigationStyle": "default"
}
}]
}],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
},
"uniIdRouter": {},
"condition": { //模式配置,仅开发期间生效
"current": 0, //当前激活的模式(list 的索引项)
"list": [{
"name": "", //模式名称
"path": "", //启动页面,必选
"query": "" //启动参数,在页面的onLoad函数里面得到
}]
}
}
【main.js(Vue3 项目无需修改)】
如果您是 Vue2 项目,请在 main.js 中引入组合式API,防止环境变量 isPC
等无法使用。
// #ifndef VUE3
import VueCompositionAPI from '@vue/composition-api';
Vue.use(VueCompositionAPI);
// #endif
【主包 pages/index/index.vue】
<template>
<div class="chat">
<button @click="getSupport">咨询客服</button>
</div>
</template>
<script>
export default {
methods: {
getSupport() {
uni.navigateTo({
url: "/pages-ai-desk/index/index"
})
}
}
}
</script>
<style lang="scss" scoped>
.chat {
height: 100%;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
</style>
【分包 pages-ai-desk/index/index.vue】
<template>
<CustomerServiceChat style="height: 100%;" />
</template>
<script>
import TUICustomerServer from '../../ai-desk-customer-uniapp/server';
import CustomerServiceChat from '../../ai-desk-customer-uniapp/components/CustomerServiceChat/index-uniapp.vue'
export default {
components: {
CustomerServiceChat
},
data() {
return {}
},
onLoad() {
this.$nextTick(() => {
// SDKAppID/userID/userSig 的获取请参考步骤4
const SDKAppID = 0;
const userID = '';
const userSig = '';
TUICustomerServer.init(SDKAppID, userID, userSig);
})
}
}
</script>
<style scoped lang="scss">
</style>
获取 SDKAppID、userID、userSig 信息后填写到 pages-ai-desk/index/index.vue
中对应的字段上。
const SDKAppID = 0;// Your SDKAppID
const userID = '';// Your userID
const userSig = '';// Your userSig
SDKAppID 信息,可通过 即时通信 IM 控制台 获取:
userID 信息,可单击 即时通信 IM 控制台 > 账号管理,切换至目标应用所在账号,创建 2 个 userID 方便后续体验聊天功能。
userSig 信息,可单击 即时通信 IM 控制台 > 开发工具 > UserSig生成&校验,填写创建的 userID,即可生成 userSig。
使用 HBuilderX 启动该项目,单击运行,可选择运行到浏览器,或者手机,或者小程序模拟器。
如果您选择了运行到微信开发者工具,但 HBuilderX 没有自动拉起微信开发者工具,请使用微信开发者工具手动打开编译后的项目,目录地址:unpackage/dist/dev/mp-weixin
。
小程序开发环境,请选择 详情 > **本地设置 **中勾选 不校验合法域名、web-view(业务域名)、TLS版本以及 HTTPS 证书。上线前请在微信公众平台 > 开发 > 开发管理 > 开发设置 > 服务器域名中进行域名配置,域名配置详见:小程序合法域名。
UserSig 是用户登录即时通信 IM 的密码,其本质是对 UserID 等信息加密后得到的密文。
UserSig 签发方式是将 UserSig 的计算代码集成到您的服务端,并提供面向项目的接口,在需要 UserSig 时由您的项目向业务服务器发起请求获取动态 UserSig。更多详情请参见 服务端生成 UserSig。
如果您打包 App / H5,需要在 pages.json 中配置 tabBar。请参考 uni-app 官网 tabBar 配置 自实现。
如果您打包小程序,因为主包体积限制,小程序默认是分包集成,如果您的 tabBar 需要自定义实现。请参考 uni-app 官网 自定义 tabBar。
请在 微信公众平台 > 开发 > 开发管理 > 开发设置 > 服务器域名 中进行域名配置。域名配置详见:小程序合法域名。
说明:
UIKit 中默认没有集成 TencentCloud-TIMPush 推送插件。TencentCloud-TIMPush 是腾讯云即时通信 IM Push 插件。目前推送支持小米、华为、荣耀、OPPO、vivo、魅族、APNs、一加、realme、iQOO 和 苹果等厂商通道。
如果您需要在 App 中集成离线推送能力,请参见 uni-app 推送 实现。
点此进入 IM 社群,享有专业工程师的支持,解决您的难题。
FAQs
chat uikit ai-desk-customer
The npm package @tencentcloud/ai-desk-customer-uniapp receives a total of 27 weekly downloads. As such, @tencentcloud/ai-desk-customer-uniapp popularity was classified as not popular.
We found that @tencentcloud/ai-desk-customer-uniapp demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.