Commit cc6fb592 by wildworker

添加默认的打开action

parent 9a94f7aa
FROM node:alpine FROM node:alpine
WORKDIR /data
COPY ./package.json . COPY ./package.json .
RUN yarn RUN yarn
COPY . .
CMD ["node","app.js"] CMD ["node","app.js"]
...@@ -14,20 +14,40 @@ app.use(static({ ...@@ -14,20 +14,40 @@ app.use(static({
})); }));
app.use(bodyParser()); app.use(bodyParser());
const sessionStorage = new Map();
const helpAll = require('./help'); const helpText = require('./config').helpText;
const replyText = (helpObj)=>{ const prefix = require('./config').prefix;
let text = '';
if(typeof helpObj === 'object'){ /**
for(let key in helpObj){ * 从多个字符集里随机抽取一个字符
text += `选择${key},${helpObj[key].text}.`; * @param textArray 多个字符串的数据
} * @returns {string} 只获取其中随机一个字符串
}else{ */
text += helpObj; const randomText = (textArray)=>{
} let index = Math.floor(Math.random() * textArray.length);
return replyBody('ASK_INF',text); return textArray[index]
}; };
/**
* 增加语气前缀
* @param {string} text 原语句
* @returns {string} 添加语气前缀后的语句
*/
const addPrefix = (text)=>{
return prefix.successParticle + ' ' + prefix.call + ' ' + prefix.selfNamed + ' ' + randomText(prefix.successNext) + ' ' + text;
};
const errorReply = ()=>{
return randomText(prefix.failParticle) + ' ' + prefix.call + ' ' + prefix.selfNamed + ' ' + randomText(prefix.failNext) + ' ' + '您可以说“如何使用智能锁”'
};
/**
* 返回body
* https://www.aligenie.com/doc/357834/yg967o
* @param type ASK_INF:信息获取 RESULT:正常完成交互的阶段并给出回复 CONFIRM:期待确认
* @param msg 播报语句
* @returns {{returnCode: string, returnValue: {executeCode: string, reply: *, resultType: *, msgInfo: string}, returnMessage: string, returnErrorSolution: string}}
*/
const replyBody = (type,msg)=>{ const replyBody = (type,msg)=>{
return { return {
"returnCode": "0", "returnCode": "0",
...@@ -41,6 +61,13 @@ const replyBody = (type,msg)=>{ ...@@ -41,6 +61,13 @@ const replyBody = (type,msg)=>{
} }
} }
}; };
/**
* 回复逻辑
* @param sessionId 会话id 一连串的对话为同一个会话id
* @param slotEntities 包含实体
* @returns {{returnCode: string, returnValue: {executeCode: string, reply: *, resultType: *, msgInfo: string}, returnMessage: string, returnErrorSolution: string}}
*/
const reply = (sessionId,slotEntities)=>{ const reply = (sessionId,slotEntities)=>{
let nowParam, nowValue; let nowParam, nowValue;
for(let slotEntity of slotEntities){ for(let slotEntity of slotEntities){
...@@ -49,28 +76,30 @@ const reply = (sessionId,slotEntities)=>{ ...@@ -49,28 +76,30 @@ const reply = (sessionId,slotEntities)=>{
nowValue = slotEntity.slotValue; nowValue = slotEntity.slotValue;
} }
} }
if(!nowParam){ // if(!nowParam){
sessionStorage.delete(sessionId); // return replyBody('ASK_INF','欢迎使用智能锁,您可以问我“如何使用智能锁”')
return replyBody('RESULT','欢迎使用智能锁,您可以问我“如何使用智能锁”') // }
} if(nowParam === 'action'){
if(nowParam === 'ask_start'){ if(nowValue === 'error'){
sessionStorage.set(sessionId,helpAll); return replyBody('ASK_INF', errorReply())
return replyText(helpAll) }else{
} return replyBody('ASK_INF', addPrefix(helpText[nowValue]))
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将调用该异步函数处理请求:
/**
* ai语音助手WEBHOOK
*/
router.post('/aiReply', async (ctx) => { router.post('/aiReply', async (ctx) => {
const params = ctx.request.body; const params = ctx.request.body;
// console.log(params); console.log(params);
if(params.utterance.substring(0,2) === '打开'){
ctx.response.body = replyBody('ASK_INF','欢迎使用智能锁,您可以问我“如何使用智能锁”')
}else{
ctx.response.body = reply(params.sessionId,params.slotEntities); ctx.response.body = reply(params.sessionId,params.slotEntities);
}
}); });
......
module.exports = {
helpText:{
"use": "欢迎使用智能锁,我是您的客服机器人小凯,您可以问我“设备配网”、“添加钥匙”、“临时密码”,请告诉我您的需要吧。",
"bind": "第一步:请在智能锁上按“*#”键进入管理模式,初始密码为“123456” 第二步:根据语音提示,按“4键进入网络设置”再按“1键连接网络” 第三步:对着天猫精灵说“天猫精灵,找队友”,根据天猫精灵提示进行回复,随后您将听到“设备连接成功”。",
"addKey": "第一步:请打开“天猫精灵”APP进入智能锁操作界面,点击“钥匙管理”按钮,再点击“添加钥匙”按钮 第二步:手机靠近门锁,根据页面设置完成后点击“确定”按钮 第三步:根据门锁语音提示录入钥匙,直到APP页面提示“钥匙添加成功”",
"tempKey": "第一步:请打开“天猫精灵”APP进入智能锁操作界面,点击“临时密码”按钮 第二步:选择密码有效时间,并根据提示完成门锁上的操作,APP将随机生成临时密码。第三步:将密码告知访客,访客可在设定有效时间内开门。",
},
prefix:{
//成功语气词
successParticle: "啦啦啦",
//失败语气词
failParticle: ["呜呜呜","嘤嘤嘤","呀呀呀"],
//称呼
call: "主人",
//自称
selfNamed: "小凯",
successNext: ["已找到您要的使用帮助","找到了您要的内容"],
failNext: ["还不会啦","还在努力学习","请以后教教我"]
}
};
version: '3' version: '3'
services: services:
frp-server: aligenie-ai:
image: aligenie-ai image: aligenie-ai
container_name: aligenie-ai container_name: aligenie-ai
restart: always restart: always
networks: networks:
- ioclubs - ioclubs
expose:
- 8000
environment:
VIRTUAL_HOST: pub.ioclubs.com,aligenie.ioclubs.com
HTTPS_METHOD: nohttps
VIRTUAL_PORT: 8000
volumes: volumes:
- ./static:/data/static - ./static:/data/static
- ./help.js:/data/help.js - ./help.js:/data/help.js
......
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": "手机靠近门锁,根据页面设置完成后点击'确定'按钮"
}
}
}
};
const funcStr = "(a,b)=>a+b";
// const func = eval(funcStr);
console.log(eval(funcStr)(2,4));
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