Commit 9a94f7aa by wildworker

用户通过回答指定数字获取客服帮助

parents
node_modules
static
.idea
FROM node:alpine
COPY ./package.json .
RUN yarn
CMD ["node","app.js"]
// 导入koa,和koa 1.x不同,在koa2中,我们导入的是一个class,因此用大写的Koa表示:
const Koa = require('koa');
const Router = require('koa-router');
const static = require('koa-static-router');
// 创建一个Koa对象表示web app本身:
const app = new Koa();
const router = new Router();
const bodyParser = require('koa-bodyparser');
app.use(static({
dir: './static', //静态资源目录对于相对入口文件index.js的路径
router: 'aligenie' //路由命名
}));
app.use(bodyParser());
const sessionStorage = new Map();
const helpAll = require('./help');
const replyText = (helpObj)=>{
let text = '';
if(typeof helpObj === 'object'){
for(let key in helpObj){
text += `选择${key},${helpObj[key].text}.`;
}
}else{
text += helpObj;
}
return replyBody('ASK_INF',text);
};
const replyBody = (type,msg)=>{
return {
"returnCode": "0",
"returnErrorSolution": "",
"returnMessage": "",
"returnValue": {
"reply": msg,
"resultType": type,
"executeCode": "SUCCESS",
"msgInfo": ""
}
}
};
const reply = (sessionId,slotEntities)=>{
let nowParam, nowValue;
for(let slotEntity of slotEntities){
if(slotEntity.liveTime === 0){
nowParam = slotEntity.intentParameterName;
nowValue = slotEntity.slotValue;
}
}
if(!nowParam){
sessionStorage.delete(sessionId);
return replyBody('RESULT','欢迎使用智能锁,您可以问我“如何使用智能锁”')
}
if(nowParam === 'ask_start'){
sessionStorage.set(sessionId,helpAll);
return replyText(helpAll)
}
if(nowParam === 'sys.anyNumber'){
let helpObj = sessionStorage.get(sessionId);
if(!helpObj || !helpObj[nowValue] || !helpObj[nowValue].detail){
return replyBody('RESULT','对不起,选择不合法')
}
sessionStorage.set(sessionId,helpObj[nowValue].detail);
return replyText(helpObj[nowValue].detail)
}
};
// 对于任何请求,app将调用该异步函数处理请求:
router.post('/aiReply', async (ctx) => {
const params = ctx.request.body;
// console.log(params);
ctx.response.body = reply(params.sessionId,params.slotEntities);
});
// 加载路由中间件
//解释:app.use 加载用于处理http請求的middleware(中间件),当一个请求来的时候,会依次被这些 middlewares处理。
app.use(router.routes());
// 在端口3000监听:
app.listen(8000, () => {
console.log('server start at port 8000')
});
version: '3'
services:
frp-server:
image: aligenie-ai
container_name: aligenie-ai
restart: always
networks:
- ioclubs
volumes:
- ./static:/data/static
- ./help.js:/data/help.js
networks:
ioclubs:
external: true
module.exports = {
"1": {
"text": "使用帮助",
"detail": {
"1": {
"text": "智能锁如何设置",
"detail": "对就这样设置"
},
"2": {
"text": "智能锁使用方法",
"detail": "按照说明书上进入使用"
}
}
},
"2": {
"text": "配网帮助",
"detail": {
"1": {
"text": "如何连接智能锁",
"detail": "关于如何连接智能锁,第一步:请在智能锁上按'*#'键进入管理模式,初始密码为'123456'第二步:根据语音提示,按'4键进入网络设置'再按'1键连接网络'第三步:对着天猫精灵说'天猫精灵,找队友',根据天猫精灵提示进行回复,随后您将听到'设备连接成功'。"
},
"2": {
"text": "如何将智能锁联网",
"detail": "关于如何智能锁联网,第一步:请在智能锁上按'*#'键进入管理模式,初始密码为'123456'第二步:根据语音提示,按'4键进入网络设置'再按'1键连接网络'第三步:对着天猫精灵说'天猫精灵,找队友',根据天猫精灵提示进行回复,随后您将听到'设备连接成功'。"
}
}
},
"3": {
"text": "添加钥匙",
"detail": {
"1": {
"text": "如何添加指纹",
"detail": "请打开'天猫精灵'APP进入智能锁操作界面,点击'钥匙管理'按钮,再点击'添加钥匙'按钮"
},
"2": {
"text": "智能锁怎么录指纹?",
"detail": "手机靠近门锁,根据页面设置完成后点击'确定'按钮"
}
}
}
};
{
"name": "aligenie-ai",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"koa": "^2.11.0",
"koa-bodyparser": "^4.2.1",
"koa-router": "^8.0.8",
"koa-static-router": "^1.3.0"
}
}
需要新建static目录,存放天猫精灵的认证文件
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment