wechaty / puppet-whatsapp

Wechaty Puppet for Whatsapp
https://npmjs.com/package/wechaty-puppet-whatsapp
Apache License 2.0
24 stars 17 forks source link

掉线的时候消息丢失,不可控 #208

Open su-chang opened 2 years ago

su-chang commented 2 years ago

测试结果文档链接(待补充):https://k0auuqcihb.feishu.cn/wiki/wikcnVwzIb24hmiW6upptq6Sfsw

解决方案

目前观察发现 WhatsApp Web 端在手机离线的情况下接收到的消息都会同步成功。

whatsapp-web.js 的 SDK 中提供接口 fetchMessage(),参见:https://docs.wwebjs.dev/Chat.html#fetchMessages

考虑在 puppet-whatsapp 中触发 READY 事件前,针对当前所有会话拉取近期的消息:

su-chang commented 2 years ago

目前仅在触发ready事件之前才会同步消息。

可能还需要加一个定时任务来定时拉取近期的消息,以便及时同步丢失的消息。

su-chang commented 2 years ago

whatsapp-web.js 的 SDK 中提供接口 fetchMessage(),参见:https://docs.wwebjs.dev/Chat.html#fetchMessages

待优化

接口 fetchMessage()只支持 limit 参数,导致每次同步消息时都会拉取所有会话的所有消息。

目前的优化方案只是根据 timestamp 属性来判断是否进行执行 onMessage 函数。

最好是 whatsapp-web.js 能支持以 timestamp 为参数来调用 fetchMessage() 接口。

su-chang commented 2 years ago

针对历史消息需要增加最小时长,来控制向 Wechaty emit 消息的数量,暂定 3 天。

lijiarui commented 2 years ago

We should always put the public link in the issue, or this issue will be meaningless.