Skip to content

Commit

Permalink
Merge branch 'master' of github.com:scp10011/xiaoai_hook
Browse files Browse the repository at this point in the history
  • Loading branch information
scp10011 committed Jun 5, 2020
2 parents a60b03e + 406d349 commit 1c95296
Showing 1 changed file with 1 addition and 319 deletions.
320 changes: 1 addition & 319 deletions node-red-demo.json
Original file line number Diff line number Diff line change
@@ -1,319 +1 @@
[
{
"id": "d00bf2f4.065a6",
"type": "tab",
"label": "流程1",
"disabled": false,
"info": ""
},
{
"id": "ef681dc8.d925d",
"type": "http in",
"z": "d00bf2f4.065a6",
"name": "",
"url": "/xiaoai_hook/event",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 1950,
"y": 320,
"wires": [
[
"d74ed5df.70e278",
"4b2767a0.b5b7d8",
"206a348f.0a664c"
]
]
},
{
"id": "d74ed5df.70e278",
"type": "debug",
"z": "d00bf2f4.065a6",
"name": "全局调试",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 2220,
"y": 280,
"wires": []
},
{
"id": "73005c96.da10e4",
"type": "http in",
"z": "d00bf2f4.065a6",
"name": "",
"url": "/xiaoai_hook/keyword",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 1950,
"y": 480,
"wires": [
[
"1dbc59d1.310b76"
]
]
},
{
"id": "869b1c46.24f34",
"type": "http response",
"z": "d00bf2f4.065a6",
"name": "",
"statusCode": "200",
"headers": {},
"x": 2420,
"y": 480,
"wires": []
},
{
"id": "1dbc59d1.310b76",
"type": "function",
"z": "d00bf2f4.065a6",
"name": "小爱拦截词",
"func": "// 多个关键词以竖线分割\nmsg.payload = `厕所|卫生间|没有|未知`\nreturn msg",
"outputs": 1,
"noerr": 0,
"x": 2230,
"y": 480,
"wires": [
[
"869b1c46.24f34"
]
]
},
{
"id": "4b2767a0.b5b7d8",
"type": "function",
"z": "d00bf2f4.065a6",
"name": "处理捕获指令",
"func": "// 指令词列表\n// 一行一个设备,对于一个设备的多个指令词可用,分割\nconst list = [\n '厕所有人吗,卫生间有人吗',\n]\n\n\n// === 以下内容大多数情况不用改 ====\nlet queries = []\ntry {\n queries = JSON.parse(msg.payload.res).response.answer[0].text;\n} catch (e) {\n}\nmsg.queries = queries\nmsg.list = list\nmsg.matched = !!list.filter((item, index) => {\n matched = ~item.indexOf(queries).length\n matched && (msg.matched_index = index)\n return matched\n}).length\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 2240,
"y": 320,
"wires": [
[
"378f06e8.9822da"
]
]
},
{
"id": "7df9fe57.47dcf",
"type": "switch",
"z": "d00bf2f4.065a6",
"name": "",
"property": "matched_index",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 2590,
"y": 620,
"wires": [
[
"263d7b44.fbe094"
]
]
},
{
"id": "7b246ac2.9611e4",
"type": "comment",
"z": "d00bf2f4.065a6",
"name": "在这里统一配置响应词以及TTS文案",
"info": "",
"x": 2300,
"y": 400,
"wires": []
},
{
"id": "378f06e8.9822da",
"type": "switch",
"z": "d00bf2f4.065a6",
"name": "",
"property": "matched",
"propertyType": "msg",
"rules": [
{
"t": "false"
},
{
"t": "true"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 2430,
"y": 320,
"wires": [
[
"2beaee9a.e73382"
],
[
"7df9fe57.47dcf"
]
]
},
{
"id": "6d18ab6b.c01194",
"type": "comment",
"z": "d00bf2f4.065a6",
"name": "在这里配置小爱的拦截词",
"info": "",
"x": 2270,
"y": 520,
"wires": []
},
{
"id": "8ae85959.3aba48",
"type": "comment",
"z": "d00bf2f4.065a6",
"name": "卫生间有人吗",
"info": "",
"x": 2770,
"y": 400,
"wires": []
},
{
"id": "2beaee9a.e73382",
"type": "function",
"z": "d00bf2f4.065a6",
"name": "默认回复",
"func": "msg.payload ={method: \"TTS\", jsonrpc: \"2.0\", id: 0, params: {token: \"123456\", msg: \"厕所没人\"}}\ntry{\n const res = JSON.parse(msg.payload.res)\n msg.payload.params.msg = `嘿嘿嘿,${res.answer[0].text}`\n}\ncatch(e){\n msg.payload.params.msg = '嘿嘿嘿,你说的是啥'\n}\n\nreturn msg",
"outputs": 1,
"noerr": 0,
"x": 2920,
"y": 320,
"wires": [
[
"76dd1275.20d05c"
]
]
},
{
"id": "206a348f.0a664c",
"type": "http response",
"z": "d00bf2f4.065a6",
"name": "",
"statusCode": "200",
"headers": {},
"x": 2220,
"y": 360,
"wires": []
},
{
"id": "263d7b44.fbe094",
"type": "api-current-state",
"z": "d00bf2f4.065a6",
"name": "厕所灯",
"server": "5811c904.4fe268",
"version": 1,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "switch.wall_switch_right_158d0003a23208",
"state_type": "str",
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"blockInputOverrides": true,
"x": 2770,
"y": 440,
"wires": [
[
"8dcb9b4.86b8f68"
],
[
"a8bc775a.7aa448"
]
]
},
{
"id": "8dcb9b4.86b8f68",
"type": "function",
"z": "d00bf2f4.065a6",
"name": "有人",
"func": "msg.payload ={method: \"TTS\", jsonrpc: \"2.0\", id: 0, params: {token: \"123456\", msg: \"厕所有人\"}}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 2930,
"y": 420,
"wires": [
[
"76dd1275.20d05c"
]
]
},
{
"id": "96e6e537.5a0538",
"type": "debug",
"z": "d00bf2f4.065a6",
"name": "全局调试",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 3300,
"y": 620,
"wires": []
},
{
"id": "76dd1275.20d05c",
"type": "http request",
"z": "d00bf2f4.065a6",
"name": "TTS",
"method": "POST",
"ret": "obj",
"paytoqs": false,
"url": "http://172.16.1.15:18888/jsonrpc",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 3130,
"y": 620,
"wires": [
[
"96e6e537.5a0538"
]
]
},
{
"id": "a8bc775a.7aa448",
"type": "function",
"z": "d00bf2f4.065a6",
"name": "没人",
"func": "msg.payload ={method: \"TTS\", jsonrpc: \"2.0\", id: 0, params: {token: \"123456\", msg: \"厕所没人\"}}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 2930,
"y": 460,
"wires": [
[
"76dd1275.20d05c"
]
]
},
{
"id": "5811c904.4fe268",
"type": "server",
"z": "",
"name": "Home Assistant",
"addon": true
}
]
[{"id":"d00bf2f4.065a6","type":"tab","label":"流程1","disabled":false,"info":""},{"id":"ef681dc8.d925d","type":"http in","z":"d00bf2f4.065a6","name":"","url":"/xiaoai_hook/event","method":"post","upload":false,"swaggerDoc":"","x":1950,"y":320,"wires":[["4b2767a0.b5b7d8","206a348f.0a664c","50314ca8.255e24"]]},{"id":"d74ed5df.70e278","type":"debug","z":"d00bf2f4.065a6","name":"全局调试","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":2420,"y":400,"wires":[]},{"id":"73005c96.da10e4","type":"http in","z":"d00bf2f4.065a6","name":"","url":"/xiaoai_hook/keyword","method":"get","upload":false,"swaggerDoc":"","x":1950,"y":480,"wires":[["1dbc59d1.310b76"]]},{"id":"869b1c46.24f34","type":"http response","z":"d00bf2f4.065a6","name":"","statusCode":"200","headers":{},"x":2420,"y":480,"wires":[]},{"id":"1dbc59d1.310b76","type":"function","z":"d00bf2f4.065a6","name":"小爱拦截词","func":"// 多个关键词以竖线分割\nmsg.payload = `厕所|卫生间`\nreturn msg","outputs":1,"noerr":0,"x":2230,"y":480,"wires":[["869b1c46.24f34"]]},{"id":"4b2767a0.b5b7d8","type":"function","z":"d00bf2f4.065a6","name":"处理捕获指令","func":"// 指令词列表\n// 一行一个设备,对于一个设备的多个指令词可用,分割\nconst list = [\n '厕所有人吗,卫生间有人吗',\n]\n\n\n// === 以下内容大多数情况不用改 ====\nlet queries = []\ntry {\n queries = JSON.parse(msg.payload.res).response.answer[0].text;\n} catch (e) {\n}\nmsg.queries = queries\nmsg.list = list\nmsg.matched = !!list.filter((item, index) => {\n matched = ~item.indexOf(queries).length\n matched && (msg.matched_index = index)\n return matched\n}).length\n\nreturn msg;","outputs":1,"noerr":0,"x":2240,"y":320,"wires":[["378f06e8.9822da"]]},{"id":"7df9fe57.47dcf","type":"switch","z":"d00bf2f4.065a6","name":"","property":"matched_index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":2590,"y":620,"wires":[["263d7b44.fbe094"]]},{"id":"7b246ac2.9611e4","type":"comment","z":"d00bf2f4.065a6","name":"在这里统一配置响应词以及TTS文案","info":"","x":2300,"y":240,"wires":[]},{"id":"378f06e8.9822da","type":"switch","z":"d00bf2f4.065a6","name":"","property":"matched","propertyType":"msg","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":2430,"y":320,"wires":[["2beaee9a.e73382"],["7df9fe57.47dcf"]]},{"id":"6d18ab6b.c01194","type":"comment","z":"d00bf2f4.065a6","name":"在这里配置小爱的拦截词","info":"","x":2270,"y":520,"wires":[]},{"id":"8ae85959.3aba48","type":"comment","z":"d00bf2f4.065a6","name":"卫生间有人吗","info":"","x":2770,"y":400,"wires":[]},{"id":"2beaee9a.e73382","type":"function","z":"d00bf2f4.065a6","name":"默认回复","func":"answer = msg.payload.answer || '你说的是啥'\nmsg.payload ={method: \"TTS\", jsonrpc: \"2.0\", id: 0, params: {token: \"123456\", msg: answer}}\nreturn msg","outputs":1,"noerr":0,"x":2920,"y":320,"wires":[["76dd1275.20d05c"]]},{"id":"206a348f.0a664c","type":"http response","z":"d00bf2f4.065a6","name":"","statusCode":"200","headers":{},"x":2220,"y":280,"wires":[]},{"id":"263d7b44.fbe094","type":"api-current-state","z":"d00bf2f4.065a6","name":"厕所灯","server":"5811c904.4fe268","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.wall_switch_right_158d0003a23208","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":true,"x":2770,"y":440,"wires":[["8dcb9b4.86b8f68"],["a8bc775a.7aa448"]]},{"id":"8dcb9b4.86b8f68","type":"function","z":"d00bf2f4.065a6","name":"有人","func":"place = msg.queries.startsWith(\"厕\") ? \"厕所\" : \"卫生间\"\nmsg.payload ={method: \"TTS\", jsonrpc: \"2.0\", id: 0, params: {token: \"123456\", msg: `${place}有人,空闲时我会提醒你的`}}\nreturn msg;","outputs":1,"noerr":0,"x":2930,"y":420,"wires":[["76dd1275.20d05c","d27e8eb5.d38dc"]]},{"id":"96e6e537.5a0538","type":"debug","z":"d00bf2f4.065a6","name":"全局调试","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":3300,"y":620,"wires":[]},{"id":"76dd1275.20d05c","type":"http request","z":"d00bf2f4.065a6","name":"TTS","method":"POST","ret":"obj","paytoqs":false,"url":"http://172.16.1.15:18888/jsonrpc","tls":"","persist":false,"proxy":"","authType":"","x":3150,"y":620,"wires":[["96e6e537.5a0538"]]},{"id":"a8bc775a.7aa448","type":"function","z":"d00bf2f4.065a6","name":"没人","func":"place = msg.queries.startsWith(\"厕\") ? \"厕所\" : \"卫生间\"\nmsg.payload ={method: \"TTS\", jsonrpc: \"2.0\", id: 0, params: {token: \"123456\", msg: `${place}没人`}}\n\nreturn msg;","outputs":1,"noerr":0,"x":2930,"y":460,"wires":[["76dd1275.20d05c"]]},{"id":"50314ca8.255e24","type":"json","z":"d00bf2f4.065a6","name":"","property":"payload.res","action":"","pretty":false,"x":2230,"y":400,"wires":[["d74ed5df.70e278"]]},{"id":"d27e8eb5.d38dc","type":"ha-wait-until","z":"d00bf2f4.065a6","name":"等待厕所没人","server":"5811c904.4fe268","outputs":1,"entityId":"switch.wall_switch_right_158d0003a23208","entityIdFilterType":"exact","property":"state","comparator":"is","value":"off","valueType":"str","timeout":0,"timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":3140,"y":420,"wires":[["1e54ee5c.93e382"]]},{"id":"1e54ee5c.93e382","type":"function","z":"d00bf2f4.065a6","name":"提示停止占用","func":"place = msg.querie.startsWith(\"厕\") ? \"厕所\" : \"卫生间\"\nmsg.payload ={method: \"TTS\", jsonrpc: \"2.0\", id: 0, params: {token: \"123456\", msg: `${place}没人了,快去吧`}}\nreturn msg;","outputs":1,"noerr":0,"x":3320,"y":420,"wires":[["76dd1275.20d05c"]]},{"id":"5811c904.4fe268","type":"server","z":"","name":"Home Assistant","addon":true}]

0 comments on commit 1c95296

Please sign in to comment.