有女朋友真的很麻烦,没有女朋友又万万不能。现在机器人大行其道,为啥咱们就不能搞个机器人陪下女朋友呢,撸起袖子,说干就干。为了让广大没有编程经验的网友安心“打农药”,这次我特意选择了一个不用编程就可以实现机器人的工具,废话少说,直接上干货。
业务逻辑
业务逻辑比较简单
- 当收到女朋友消息时,秒回,安全防查岗。
- 定时给女朋友发送消息提醒她起床、吃饭,时刻关心她,爱护她。
准备工作
- 注册冰狐智能辅助账号
- 准备android手机一台
- 在android手机中安装冰狐智能辅助app并登录
详细准备过程请见这里https://aznfz.com/document/prepare
制作机器人
制作机器人使用了冰狐智能辅助的自动构建功能,可以在不编写一行代码的前提下实现聊天机器人。在开始前,请各位网友认真阅读下自动构建的文档,以便完全理解下面的制作过程。
1.创建自动构建
在网页端「移动端」/「自动构建」,新建一个名为“聊天机器人”的自动构建。
2.添加表示女朋友昵称的变量
点击配置构建按键,在“根”模块中找到“变量声明”模块,然后依次点击“编辑” - “查看/编辑变量声明”,添加gf_nickname普通变量,字符串类型,默认值填女友的微信昵称
3.创建一个自定义模块用于发送消息
点击配置构建按键,在“根”模块中添加一个“自定义模块”,修改配置属性
- desc属性改为“发送信息”
- name属性改为“sendMsg2GF”
- 选中declareVar属性,表示在该模块内部声明通用变量为后续模块使用
- params属性为模块参数,分别添加gfName、sendText表示女友昵称和待发送的文本
添加子模块
添加启动app模块,启动微信;进入微信后,需要点击底部的“微信”按钮,然后搜索目标微信名并发送消息给对方,最后返回冰狐界面,具体参数配置和细节就不再赘述了,最后我会给出所有的配置源码。
4.创建“调度”模块提醒女友起床
在“根”模块添加调度子模块,
- 模块改名为“叫女朋友起床”
- cron参数修改为“0 8 ? * MON-FRI”,表示周一至周五早上8点自动执行
- 添加调用自定义模块,调用上面创建的发送消息模块给女朋友发送消息
5.创建“调度”模块提醒女友吃午饭
和上一步一样,在“根”模块添加调度子模块
- 模块改名为“喊女朋友吃午饭”
- cron参数修改为“0 12 ? * MON-FRI”,表示周一至周五,中午12点自动执行
- 添加调用自定义模块,调用上面创建的发送消息模块给女朋友发送消息
6.自动回复女友消息
新建通知模块,当收到微信消息时系统会自动调用该模块
在“根”模块中,添加通知子模块
- desc改为“自动回复女友消息”
- packageName改为:“com.tencent.mm”,表示截获微信的通知信息
- 选中declareVar
- 添加处理项,名称为女朋友的微信昵称,对应的操作为提取消息并发送回复消息给女朋友。表示当收到女朋友的信息时,做对应的处理。
详细处理过程后续我会给出自动构建源码。
创建自动回复数据集
自动回复数据集用于当收到女友消息时,自动从该集合中挑选消息回复女友。数据集以json格式数据存放,用户只需要按格式添加和修改数据即可。
- 在网页端「微服务」/「自定义数据」,新建名为“robot_gf”的自定义数据项
- 添加数据[ ["在吗", "在的"], ["吃饭了", "吃过了"], ["人呢", "哈哈"] ]
“在吗”对应的回答为“在的”,注意只要女友的消息中包含了“在吗”都会自动回复“在的”,比如“老铁在吗?”也会自动回复“在的”
如果需要添加“在干嘛”,“在想你呢”,数据集改为[ [“在干嘛”,“在想你呢”], ["在吗", "在的"], ["吃饭了", "吃过了"], ["人呢", "哈哈"] ]
注意所有符号都为英文符号,不能填中文符号哦
自动构建源码
完整的自动构建源码如下,用户可以直接在自动构建处,点击“配置源码”把如下配置数据粘贴进去即可,注意在使用前必须把“变量声明”模块中的gf_nickname改为自己女友的微信昵称。
{
"type": "root",
"children": [{
"type": "declareVar",
"var": [{
"name": "temp",
"type": "normal",
"initType": "null",
"initValue": "null"
}, {
"name": "ret",
"type": "normal",
"initType": "null",
"initValue": "null"
}, {
"name": "view",
"type": "normal",
"initType": "null",
"initValue": "null"
}, {
"name": "viewContainer",
"type": "normal",
"initType": "null",
"initValue": "null"
}, {
"name": "item",
"type": "normal",
"initType": "null",
"initValue": "null"
}, {
"name": "index",
"type": "normal",
"initType": "null",
"initValue": "null"
}, {
"name": "data",
"type": "normal",
"initType": "string",
"initValue": ""
}, {
"name": "text",
"type": "normal",
"initType": "string",
"initValue": ""
}, {
"name": "gf_nickname",
"type": "normal",
"initType": "string",
"initValue": "女友微信昵称"
}],
"desc": "变量声明"
}, {
"type": "scheduler",
"desc": "叫女朋友起床",
"debug": false,
"returnVar": "",
"cron": "0 8 ? * MON-FRI",
"stopMainTaskBeforeStart": false,
"exeDefaultTaskWhenFinished": false,
"children": [{
"type": "callCustomModule",
"desc": "叫女朋友起床",
"debug": false,
"name": "sendMsg2GF",
"params": ["var-gf_nickname!-2", "string-小懒虫,起床啦!!"]
}],
"declareVar": true
}, {
"type": "scheduler",
"desc": "喊女朋友吃午饭",
"debug": false,
"returnVar": "",
"cron": "0 12 ? * MON-FRI",
"children": [{
"type": "callCustomModule",
"desc": "喊女朋友吃午饭",
"debug": false,
"name": "sendMsg2GF",
"params": ["var-gf_nickname!-2", "string-亲爱的,吃午饭啦!!!"]
}],
"stopMainTaskBeforeStart": false,
"exeDefaultTaskWhenFinished": false,
"declareVar": true
}, {
"type": "main",
"desc": "业务逻辑入口",
"debug": false,
"params": [],
"children": [{
"type": "log",
"desc": "日志",
"debug": false,
"logType": "log",
"info": ["string-主循环============"]
}]
}, {
"type": "notification",
"desc": "自动回复女友消息",
"debug": false,
"packageName": "com.tencent.mm",
"dealItems": [{
"key": "var-gf_nickname!-2",
"value": {
"type": "group",
"desc": "提取消息并发送回复消息给女朋友",
"debug": false,
"children": [{
"type": "callFunction",
"desc": "提取收到的信息",
"class": 1,
"debug": false,
"target": "item",
"name": "removeString",
"params": ["string-", "var-gf_nickname!-2"],
"returnValue": "text",
"returnVarIsLocal": true,
"fetchResultIndex": "-2"
}, {
"type": "getCustomData",
"desc": "获取自动回复数据集",
"debug": false,
"serviceName": "robot_gf",
"separator": "",
"fetchResultIndex": "integer--2",
"returnValue": "data",
"returnVarIsLocal": false,
"returnJsonData": true
}, {
"type": "traverse",
"desc": "根据收到的消息选择匹配的回复消息",
"class": "2",
"debug": false,
"family": [],
"descendant": [],
"clickable": false,
"target": "data",
"children": [{
"type": "if",
"desc": "条件处理",
"class": "2",
"debug": false,
"family": [],
"descendant": [],
"expr": "text.includes(item[0])",
"children": [{
"type": "js",
"desc": "js模块",
"debug": false,
"code": "text=item[1];\n"
}, {
"type": "break",
"desc": "跳出循环",
"class": 1,
"debug": false
}]
}],
"startIndex": "0",
"lastIndex": "0",
"randomPickCount": "0",
"className": ""
}, {
"type": "callCustomModule",
"desc": "给女友回复消息",
"debug": false,
"name": "sendMsg2GF",
"params": ["var-gf_nickname!-2", "var-text!-2"]
}]
}
}],
"declareVar": true,
"stopMainTaskBeforeStart": false,
"exeDefaultTaskWhenFinished": false
}, {
"type": "customModule",
"desc": "发送信息",
"debug": true,
"name": "sendMsg2GF",
"params": ["gfName", "sendText"],
"children": [{
"type": "launchApp",
"desc": "启动微信",
"debug": false,
"packageName": "com.tencent.mm",
"tag": "txt*:微信|id*:com.tencent.mm#",
"maxStep": "30",
"children": [{
"type": "click",
"desc": "点击底部“微信”按钮",
"class": 1,
"debug": false,
"tag": "txt:微信#",
"root": "",
"family": [],
"descendant": [],
"mode": "2",
"failed": "",
"maxStep": "5",
"random": true,
"duration": "500",
"beforeWait": "1000",
"afterWait": "1000"
}, {
"type": "searchAndLoopDeal",
"desc": "搜索目标的微信名并发送消息",
"debug": false,
"root": "",
"false": {
"type": "scroll",
"desc": "滚动处理",
"class": 1,
"debug": false,
"direction": "up",
"tag": "",
"family": [],
"descendant": [],
"minDistance": "0.98",
"maxDistance": "0.98",
"minScrollCount": "1",
"maxScrollCount": "1",
"minDuration": "500",
"maxDuration": "500",
"beforeWait": "1000",
"afterWait": "1000"
},
"failed": "",
"duration": "500",
"maxStep": "8",
"beforeWait": "0",
"afterWait": "0",
"dealItems": [{
"key": "txt:%&gfName#$&1",
"value": {
"type": "clickAndEnter",
"desc": "进入与目标的聊天界面",
"class": "2",
"debug": false,
"family": [],
"descendant": [],
"checkTag": "cn:android.widget.EditText#",
"mode": "2",
"failed": "",
"duration": "500",
"maxStep": "5",
"beforeWait": "0",
"afterWait": "0",
"target": "view",
"children": [{
"type": "click",
"desc": "点击消息编辑框",
"class": "2",
"debug": false,
"family": [],
"descendant": [],
"mode": "2",
"random": true,
"beforeWait": "2000",
"afterWait": "1000",
"target": "view"
}, {
"type": "paste",
"desc": "粘贴文本都消息框",
"class": 1,
"debug": false,
"data": "var-sendText!-2",
"tag": "cn:android.widget.EditText#",
"root": "",
"family": [],
"descendant": [],
"mode": "paste",
"duration": "500",
"failed": "",
"maxStep": "5",
"beforeWait": "0",
"afterWait": "2000"
}, {
"type": "click",
"desc": "发送消息",
"class": 1,
"debug": false,
"tag": "txt:发送#",
"root": "",
"family": [],
"descendant": [],
"mode": "3",
"failed": "",
"maxStep": "5",
"random": true,
"duration": "500",
"beforeWait": "1000",
"afterWait": "1000",
"false": {
"type": "log",
"desc": "日志",
"debug": false,
"logType": "log",
"info": ["string-点击发送失败"]
}
}]
}
}],
"retryCount": "0"
}, {
"type": "back2Page",
"desc": "返回冰狐",
"debug": false,
"tag": "txt:冰狐智能辅助#",
"root": "",
"backFirst": "true",
"failed": "",
"duration": "500",
"maxStep": "10",
"beforeWait": "0",
"afterWait": "0"
}]
}],
"declareVar": true
}],
"desc": "根模块",
"debug": false
}
运行机器人
请按如下步骤运行机器人
- 开启冰狐智能辅助app调试模式
- 把自动构建编译成js脚本,在网页端「移动端」/「自动构建」找到“聊天机器人”,然后点击右边的“编译”按钮,即可将自动构建编译成js脚本。
- 运行js脚本,在网页端「移动端」/「移动端脚本」找到到“聊天机器人”,然后点击右边的“运行”按钮,选择设备,开始执行脚本。
测试
- 让女友发送“在吗”给自己,然后看看是否能自动回复
- 根据调度的时间,看早上和中午是否会在给定时间给女友发送信息
结束语
一个陪女友聊天的机器人打造完工啦,各位有任何问题,欢迎在评论区浏览,有问必答哈!