萝卜的构思,我修改一下,
企业微信上面留言,不管是文本内容还是语音内容都可以,然后NR会自动将这些消息保存下来;
当触发读取消息后,这里的触发可以是一个米家小饼干,从已保存的记录中提取数据并生成TTS消息,让音箱播放;
留言获取后会自动清空;
[
{
"id": "efec3d7c.9b731",
"type": "xiaoai-tts",
"z": "ccf03ab3.fc74a8",
"name": "",
"xiaoai": "40bcf6b9.1ee278",
"tts": "",
"device": "3434d59f",
"x": 520,
"y": 460,
"wires": [
[
"34445db1.286572"
],
[
"34445db1.286572"
]
]
},
{
"id": "34445db1.286572",
"type": "debug",
"z": "ccf03ab3.fc74a8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 690,
"y": 460,
"wires": []
},
{
"id": "b2b6247b.780878",
"type": "bizwechat-input",
"z": "ccf03ab3.fc74a8",
"name": "",
"bizwechat": "8a940403.c886a8",
"x": 190,
"y": 380,
"wires": [
[
"8357d7a1.59bac8"
]
]
},
{
"id": "8357d7a1.59bac8",
"type": "function",
"z": "ccf03ab3.fc74a8",
"name": "保存留言",
"func": "/**\n 时间戳\n 对Date的扩展,将 Date 转化为指定格式的String\n 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,\n 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)\n*/\nDate.prototype.Format = function(fmt){ //author: meizz\n var o = {\n \"M+\" : this.getMonth()+1, //月份\n \"d+\" : this.getDate(), //日\n \"h+\" : this.getHours(), //小时\n \"m+\" : this.getMinutes(), //分\n \"s+\" : this.getSeconds(), //秒\n \"q+\" : Math.floor((this.getMonth()+3)/3), //季度\n \"S\" : this.getMilliseconds() //毫秒\n };\n if(/(y+)/.test(fmt))\n fmt=fmt.replace(RegExp.$1, (this.getFullYear()+\"\").substr(4 - RegExp.$1.length));\n for(var k in o)\n if(new RegExp(\"(\"+ k +\")\").test(fmt))\n fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : ((\"00\"+ o[k]).substr((\"\"+ o[k]).length)));\n return fmt;\n};\n\nvar FromUserName = {\n '111111':'三木'\n}\n\n//判断是打开企业微信后并发送了消息\nif(msg.message.MsgType != \"event\"){\n //判断是有内容的消息\n if(msg.message.AsrContent || msg.message.Content){\n var message = \"\"\n //如果是语音消息\n if(msg.message.AsrContent) message = msg.message.AsrContent[0];\n //如果是文本消息\n if(msg.message.Content) message = msg.message.Content;\n //获取未读的消息记录\n var Message = flow.get(\"TTS_Message\") || [];\n //统计消息数量\n var i = Message.length;\n //增加新消息\n Message[i] = {};\n Message[i]['FromUserName'] = FromUserName[msg.message.FromUserName];\n Message[i]['CreateTime'] = new Date().Format(\"MM月dd日hh点mm分\");\n Message[i]['Content'] = message;\n //保存\n flow.set(\"TTS_Message\", Message);\n msg.payload = Message;\n return msg;\n }\n}\n\n",
"outputs": 1,
"noerr": 0,
"x": 350,
"y": 380,
"wires": [
[
"b63f0510.079cf8"
]
]
},
{
"id": "b63f0510.079cf8",
"type": "debug",
"z": "ccf03ab3.fc74a8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 510,
"y": 380,
"wires": []
},
{
"id": "6470267.594d9d8",
"type": "inject",
"z": "ccf03ab3.fc74a8",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 190,
"y": 500,
"wires": [
[
"b225c74.5a80238"
]
]
},
{
"id": "b225c74.5a80238",
"type": "function",
"z": "ccf03ab3.fc74a8",
"name": "读取留言",
"func": "//获取未读留言记录\nvar Message = flow.get(\"TTS_Message\");\n//销毁留言记录\nflow.set(\"TTS_Message\",[]);\n//计算留言数量\nvar i = Message.length;\nvar TTS = \"\";\n//如果存在未读留言\nif(i>0){\n //构造TTS内容\n var message= \"\";\n for(var a=0;a<i;a++){\n message += `${Message[a]['FromUserName']}于${Message[a]['CreateTime']}留言说:${Message[a]['Content']}。`;\n }\n TTS = \"您当前共有\"+ i +\"条未读消息,下面开始为您播报:\" + message;\n}else{\n TTS = \"您当前没有留言消息\"\n}\nmsg.payload = TTS;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 350,
"y": 460,
"wires": [
[
"b63f0510.079cf8",
"efec3d7c.9b731"
]
]
},
{
"id": "b97df726.b550e8",
"type": "function",
"z": "ccf03ab3.fc74a8",
"name": "用触发节点代替",
"func": "\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 160,
"y": 460,
"wires": [
[
"b225c74.5a80238"
]
]
},
{
"id": "40bcf6b9.1ee278",
"type": "xiaoai-tts-configurator",
"z": "",
"name": "导出专用",
"username": "11111",
"password": "111111"
},
{
"id": "8a940403.c886a8",
"type": "bizwechat-configurator",
"z": "",
"name": "导出专用",
"port": "",
"corpid": "",
"agentid": "",
"corpsecret": "",
"url": "",
"token": "",
"aeskey": "",
"client_id": "",
"client_secret": ""
}
]