feat: add "multi file auth state" implementation

1. add multi file auth state since it's far more efficient than single state
2. deprecate single file auth state (please don't use it anymore)
This commit is contained in:
Adhiraj Singh
2022-05-22 21:21:35 +05:30
parent a8e209705a
commit 06437e182d
7 changed files with 177 additions and 88 deletions

View File

@@ -1,5 +1,5 @@
import { Boom } from '@hapi/boom'
import makeWASocket, { AnyMessageContent, delay, DisconnectReason, fetchLatestBaileysVersion, makeInMemoryStore, MessageRetryMap, useSingleFileAuthState } from '../src'
import makeWASocket, { AnyMessageContent, delay, DisconnectReason, fetchLatestBaileysVersion, makeInMemoryStore, MessageRetryMap, useMultiFileAuthState } from '../src'
import MAIN_LOGGER from '../src/Utils/logger'
const logger = MAIN_LOGGER.child({ })
@@ -21,10 +21,9 @@ setInterval(() => {
store?.writeToFile('./baileys_store_multi.json')
}, 10_000)
const { state, saveState } = useSingleFileAuthState('./auth_info_multi.json')
// start a connection
const startSock = async() => {
const { state, saveCreds } = await useMultiFileAuthState('baileys_auth_info')
// fetch latest version of WA Web
const { version, isLatest } = await fetchLatestBaileysVersion()
console.log(`using WA v${version.join('.')}, isLatest: ${isLatest}`)
@@ -94,7 +93,7 @@ const startSock = async() => {
console.log('connection update', update)
})
// listen for when the auth credentials is updated
sock.ev.on('creds.update', saveState)
sock.ev.on('creds.update', saveCreds)
return sock
}