feat: add periodic version check with soft reconnection

Implements automatic version updates that are transparent to users:

- Checks for new WhatsApp Web version every 6 hours (configurable)
- When new version detected, saves it for next natural reconnection
- Emits 'version.update' event so users can track updates
- No disconnection required - WhatsApp naturally reconnects every 30min-2h
- Cleans up interval when socket closes

Configuration:
```typescript
const sock = await makeWASocketAutoVersion({
    auth: state,
    versionCheckIntervalMs: 6 * 60 * 60 * 1000 // 6 hours (default)
})

sock.ev.on('version.update', ({ currentVersion, newVersion, isCritical }) => {
    console.log(`New version: ${newVersion.join('.')}`)
})
```
This commit is contained in:
Claude
2026-01-21 16:51:39 +00:00
parent 76e080daec
commit 805fdd3525
4 changed files with 122 additions and 7 deletions
+12
View File
@@ -107,6 +107,18 @@ export type BaileysEventMap = {
/** Settings and actions sync events */
'chats.lock': { id: string; locked: boolean }
/**
* Emitted when a new WhatsApp Web version is detected.
* The new version will be used on the next reconnection (soft update).
*/
'version.update': {
/** Previous version */
currentVersion: [number, number, number]
/** New version detected */
newVersion: [number, number, number]
/** Whether the update is critical (major version change) */
isCritical: boolean
}
'settings.update':
| { setting: 'unarchiveChats'; value: boolean }
| { setting: 'locale'; value: string }
+7
View File
@@ -56,6 +56,13 @@ export type SocketConfig = {
* @default false
*/
fetchLatestVersion: boolean
/**
* Interval in milliseconds to check for new WhatsApp Web versions.
* When a new version is detected, it will be used on the next reconnection.
* Set to 0 to disable periodic checks.
* @default 21600000 (6 hours)
*/
versionCheckIntervalMs: number
/** override browser config */
browser: WABrowserDescription
/** agent used for fetch requests -- uploading/downloading media */