17

居然有人能忘记吃饭?写个微信机器人提醒他

 3 years ago
source link: https://www.xilidou.com/2019/05/07/wx-bot/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

居然有人能忘记吃饭?写个微信机器人提醒他

2019-05-072020-11-17

175

居然有人忘记吃饭???

img

为了解决这个问题,我写了一个微信机器人到点就提醒他吃饭。

Github 地址

git clone https://github.com/diaozxin007/remindEat

修改 config/default.json 里面的 ‘toName’ 为要提醒人的备注名称。

cd remindEat
npm install

wechaty 使用了无头浏览器,安装的过程中会到 google 下载 chromium。如果遇到下载不成功的错误。可以尝试

export PUPPETEER_DOWNLOAD_HOST=https://storage.googleapis.com.cnpmjs.org
npm install

编译完成后:

node remindEat.js

如果在 ubuntu 上启动报错缺少包,可以参考 puppeteer/docs/troubleshooting.md

到时候对方应该不会忘记吃饭了。

实现原理:

这个机器人主要使用两个库:

其实核心的原理,就在 wechaty 登录以后,注册了一个定时任务。这个定时任务,用于在饭点的时候,注册另外一个 schedule ,同时这个 schedule 是为了实现每分钟一次的提示。

当对方按照指定的话术服务短信的时候,我们只需要调用每分钟提醒一次的 schedule cancel() 方法。

希望每一个人都能按时吃饭,谢谢大家。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK