Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
aligenie-ai
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
twb
aligenie-ai
Commits
ec0631cf
Commit
ec0631cf
authored
Feb 26, 2020
by
wildworker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加项目数据库配置
添加日志记录当前服务器接收和服务器返回
parent
9e244171
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
156 additions
and
28 deletions
+156
-28
Provider.js
+10
-4
Public.js
+14
-2
Util/replyFunc.js
+23
-16
config.js
+26
-2
dao/ProjectDao.js
+20
-0
docker-compose.yml
+3
-3
model/mysql/Project.js
+34
-0
text/10001.js
+3
-1
text/demo.js
+23
-0
No files found.
Provider.js
View file @
ec0631cf
const
Provider
=
require
(
'iot-cloud-core'
).
BASE
.
Provider
;
const
db_project
=
require
(
'./model/mysql/Project'
);
const
dao_project
=
require
(
'./dao/ProjectDao'
);
const
public_class
=
require
(
'./Public'
);
class
TESTProvider
extends
Provider
{
constructor
(){
super
(
"ApiSign"
);
class
AIProvider
extends
Provider
{
constructor
(
dbManager
){
super
(
"AligenieAi"
,
dbManager
);
this
.
registerModel
(
db_project
);
this
.
registerDao
(
"project"
,
dao_project
);
this
.
setPublicClass
(
public_class
);
}
}
module
.
exports
=
TEST
Provider
;
module
.
exports
=
AI
Provider
;
Public.js
View file @
ec0631cf
const
PublicFunBase
=
require
(
'iot-cloud-core'
).
BASE
.
PublicFunBase
;
const
replyFunc
=
require
(
'./replyFunc.js'
);
const
replyFunc
=
require
(
'./
Util/
replyFunc.js'
);
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
NodeRSA
=
require
(
'node-rsa'
);
const
LOG
=
require
(
'iot-cloud-core'
).
LOG
;
//解密私钥
const
privateKey
=
new
NodeRSA
(
fs
.
readFileSync
(
path
.
resolve
(
__dirname
,
'rsa'
,
'rsa_private_key.pem'
)));
privateKey
.
setOptions
({
...
...
@@ -14,15 +16,25 @@ privateKey.setOptions({
});
const
{
prefixText
,
helpText
}
=
require
(
'./text/demo.js'
);
class
Public
extends
PublicFunBase
{
async
reply
(
data
)
{
// console.log(data.params.securityQuery);
//解密后的json数据
const
decryptJson
=
privateKey
.
decrypt
(
data
.
params
.
securityQuery
,
'json'
);
LOG
.
info
(
'receive'
,
decryptJson
);
const
appid
=
data
.
params
.
appid
;
let
configPath
=
await
this
.
dao
.
get
(
"project"
).
findConfigById
({
appid
:
appid
});
if
(
!
configPath
){
configPath
=
'./text/demo.js'
;
}
const
{
prefixText
,
helpText
}
=
require
(
configPath
);
const
replyData
=
replyFunc
(
decryptJson
,
prefixText
,
helpText
);
LOG
.
info
(
'replyData'
,
replyData
);
return
{
sourceData
:
true
,
data
:
reply
Func
(
decryptJson
)
data
:
reply
Data
};
}
}
...
...
replyFunc.js
→
Util/
replyFunc.js
View file @
ec0631cf
// const helpText = require('./config').helpText;
// const prefix = require('./config').prefix;
const
{
helpText
,
prefix
}
=
require
(
'./help.js'
);
/**
* 从多个字符集里随机抽取一个字符
* @param textArray 多个字符串的数据
* @returns {string} 只获取其中随机一个字符串
*/
const
randomText
=
(
textArray
)
=>
{
if
(
textArray
instanceof
Array
){
//随机一个下标
let
index
=
Math
.
floor
(
Math
.
random
()
*
textArray
.
length
);
return
textArray
[
index
]
}
else
{
return
textArray
}
};
/**
* 增加语气前缀
* @param {object} prefixText 前缀对象
* @param {string} text 原语句
* @returns {string} 添加语气前缀后的语句
*/
const
addPrefix
=
(
text
)
=>
{
return
prefix
.
successParticle
+
' '
+
prefix
.
call
+
' '
+
prefix
.
selfNamed
+
' '
+
randomText
(
prefix
.
successNext
)
+
' '
+
text
;
const
addPrefix
Text
=
(
prefixText
,
text
)
=>
{
return
prefix
Text
.
successParticle
+
' '
+
prefixText
.
call
+
' '
+
prefixText
.
selfNamed
+
' '
+
randomText
(
prefixText
.
successNext
)
+
' '
+
text
;
};
/**
* @param {object} prefixText 前缀对象
* @param {string} text 原语句
* 增加失败语气前缀
* @returns {string} 添加语气前缀后的语句
*/
const
errorReply
=
()
=>
{
return
randomText
(
prefix
.
failParticle
)
+
' '
+
prefix
.
call
+
' '
+
prefix
.
selfNamed
+
' '
+
randomText
(
prefix
.
failNext
)
+
' '
+
'您可以说“如何使用智能锁”'
const
errorReply
=
(
prefixText
,
text
=
'您可以说“如何使用智能锁”'
)
=>
{
return
randomText
(
prefix
Text
.
failParticle
)
+
' '
+
prefixText
.
call
+
' '
+
prefixText
.
selfNamed
+
' '
+
randomText
(
prefixText
.
failNext
)
+
' '
+
text
};
/**
...
...
@@ -52,14 +56,17 @@ const replyBody = (type, msg)=>{
/**
* 回复逻辑
* @param sessionId 会话id 一连串的对话为同一个会话id
* @param params.sessionId 会话id 一连串的对话为同一个会话id
* @param params.slotEntities 包含实体
* @param slotEntities 包含实体
* @param prefixText 措辞前缀对象
* @param helpText 帮助文本
* @returns {{returnCode: string, returnValue: {executeCode: string, reply: *, resultType: *, msgInfo: string}, returnMessage: string, returnErrorSolution: string}}
*/
const
replyFunc
=
(
params
)
=>
{
const
replyFunc
=
(
params
,
prefixText
,
helpText
)
=>
{
const
{
sessionId
,
slotEntities
}
=
params
;
if
(
!
sessionId
||
!
slotEntities
){
return
replyBody
(
'ASK_INF'
,
errorReply
())
return
replyBody
(
'ASK_INF'
,
errorReply
(
prefixText
))
}
let
nowParam
,
nowValue
;
for
(
let
slotEntity
of
slotEntities
){
...
...
@@ -68,14 +75,14 @@ const replyFunc = (params)=>{
nowValue
=
slotEntity
.
slotValue
;
}
}
// if(
!nowParam){
// return replyBody('ASK_INF','欢迎使用智能锁,您可以问我“如何使用智能锁”'
)
//
}
if
(
!
nowParam
||
!
nowParam
){
return
replyBody
(
'ASK_INF'
,
errorReply
(
prefixText
)
)
}
if
(
nowParam
===
'action'
){
if
(
nowValue
===
'error'
){
return
replyBody
(
'ASK_INF'
,
errorReply
())
return
replyBody
(
'ASK_INF'
,
errorReply
(
prefixText
))
}
else
{
return
replyBody
(
'ASK_INF'
,
addPrefix
(
helpText
[
nowValue
]))
return
replyBody
(
'ASK_INF'
,
addPrefix
Text
(
prefixText
,
helpText
[
nowValue
]))
}
}
};
...
...
config.js
View file @
ec0631cf
const
path
=
require
(
'path'
);
module
.
exports
=
{
db
:{
mysql
:{
dbname
:
process
.
env
.
MYSQL_DATABASE
||
'aligenie_ai'
,
username
:
process
.
env
.
MYSQL_USERNAME
||
'root'
,
password
:
process
.
env
.
MYSQL_PASSWORD
||
'111111'
,
tablePrefix
:
'ai'
,
options
:{
host
:
process
.
env
.
MYSQL_HOST
||
'127.0.0.1'
,
pool
:
{
max
:
5
,
min
:
0
,
idle
:
10000
},
dialectOptions
:
{
charset
:
'utf8mb4'
},
define
:
{
charset
:
'utf8mb4'
,
collate
:
'utf8mb4_unicode_ci'
},
timezone
:
'+08:00'
}
},
},
port
:
3000
,
provider
:
require
(
'./Provider'
),
needLog
:
false
,
componentName
:
"ai"
,
customUrl
:
"ai"
,
componentName
:
'ai'
,
customUrl
:
'ai'
,
communications
:[
'HTTPCOM'
,
]
...
...
dao/ProjectDao.js
0 → 100644
View file @
ec0631cf
const
DaoBase
=
require
(
'iot-cloud-core'
).
BASE
.
DaoBase
;
class
ProjectDao
extends
DaoBase
{
// 根据appid获取配置文件路径
async
findConfigById
(
data
)
{
this
.
checkKeyExists
(
data
,
'appid'
);
let
condition
=
{
raw
:
true
,
where
:{
appid
:
data
.
appid
,
status
:
1
,
}
};
return
await
this
.
models
.
mysql
.
project
.
findOne
(
condition
);
}
}
module
.
exports
=
ProjectDao
;
docker-compose.yml
View file @
ec0631cf
...
...
@@ -2,7 +2,7 @@ version: '3'
services
:
aligenie-ai
:
image
:
registry.cn-hangzhou.aliyuncs.com/ugen-app/aligenie-ai:1.0
image
:
registry.cn-hangzhou.aliyuncs.com/ugen-app/aligenie-ai:1.0
.0
container_name
:
aligenie-ai
restart
:
always
networks
:
...
...
@@ -14,8 +14,8 @@ services:
HTTPS_METHOD
:
nohttps
VIRTUAL_PORT
:
3000
volumes
:
-
./static:/data/static
-
./help.js:/data/help.js
#
- ./static:/data/static
#
- ./help.js:/data/help.js
networks
:
ioclubs
:
external
:
true
model/mysql/Project.js
0 → 100644
View file @
ec0631cf
const
MysqlBase
=
require
(
'iot-cloud-core'
).
DB
.
MysqlBase
;
const
Sequelize
=
require
(
'sequelize'
);
class
Project
extends
MysqlBase
{
init
()
{
let
model
=
this
.
createTable
(
"project"
,
{
appid
:
{
type
:
Sequelize
.
STRING
(
24
),
allowNull
:
false
},
config_file
:
{
type
:
Sequelize
.
STRING
(
64
),
allowNull
:
false
},
status
:
{
type
:
Sequelize
.
INTEGER
(
1
),
allowNull
:
false
}
},
{
timestamps
:
true
,
createdAt
:
'create_time'
,
updatedAt
:
'update_time'
,
freezeTableName
:
true
,
indexes
:
[
{
unique
:
true
,
fields
:
[
'appid'
]
}
]
});
return
model
;
}
}
module
.
exports
=
Project
;
help
.js
→
text/10001
.js
View file @
ec0631cf
...
...
@@ -5,7 +5,7 @@ module.exports = {
"addKey"
:
"第一步:请打开“天猫精灵”APP进入智能锁操作界面,点击“钥匙管理”按钮,再点击“添加钥匙”按钮 第二步:手机靠近门锁,根据页面设置完成后点击“确定”按钮 第三步:根据门锁语音提示录入钥匙,直到APP页面提示“钥匙添加成功”"
,
"tempKey"
:
"第一步:请打开“天猫精灵”APP进入智能锁操作界面,点击“临时密码”按钮 第二步:选择密码有效时间,并根据提示完成门锁上的操作,APP将随机生成临时密码。第三步:将密码告知访客,访客可在设定有效时间内开门。"
,
},
prefix
:{
prefix
Text
:{
//成功语气词
successParticle
:
"啦啦啦"
,
//失败语气词
...
...
@@ -14,7 +14,9 @@ module.exports = {
call
:
"主人"
,
//自称
selfNamed
:
"小凯"
,
//成功措辞
successNext
:
[
"已找到您要的使用帮助"
,
"找到了您要的内容"
],
//失败措辞
failNext
:
[
"还不会啦"
,
"还在努力学习"
,
"请以后教教我"
]
}
...
...
text/demo.js
0 → 100644
View file @
ec0631cf
module
.
exports
=
{
helpText
:{
"use"
:
"欢迎使用智能锁,我是您的客服机器人小凯,您可以问我“设备配网”、“添加钥匙”、“临时密码”,请告诉我您的需要吧。"
,
"bind"
:
"第一步:请在智能锁上按“*#”键进入管理模式,初始密码为“123456” 第二步:根据语音提示,按“4键进入网络设置”再按“1键连接网络” 第三步:对着天猫精灵说“天猫精灵,找队友”,根据天猫精灵提示进行回复,随后您将听到“设备连接成功”。"
,
"addKey"
:
"第一步:请打开“天猫精灵”APP进入智能锁操作界面,点击“钥匙管理”按钮,再点击“添加钥匙”按钮 第二步:手机靠近门锁,根据页面设置完成后点击“确定”按钮 第三步:根据门锁语音提示录入钥匙,直到APP页面提示“钥匙添加成功”"
,
"tempKey"
:
"第一步:请打开“天猫精灵”APP进入智能锁操作界面,点击“临时密码”按钮 第二步:选择密码有效时间,并根据提示完成门锁上的操作,APP将随机生成临时密码。第三步:将密码告知访客,访客可在设定有效时间内开门。"
,
},
prefixText
:{
//成功语气词
successParticle
:
"啦啦啦"
,
//失败语气词
failParticle
:
[
"呜呜呜"
,
"嘤嘤嘤"
,
"呀呀呀"
],
//称呼
call
:
"主人"
,
//自称
selfNamed
:
"小凯"
,
//成功措辞
successNext
:
[
"已找到您要的使用帮助"
,
"找到了您要的内容"
],
//失败措辞
failNext
:
[
"还不会啦"
,
"还在努力学习"
,
"请以后教教我"
]
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment