mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: implement in memory store
1. the store works as a temporary store for connection data such as chats, messages & contacts 2. the store is primarily meant to illustrate the usage of the event emitter as a way to construct the state of the connection. This will likely be very inefficient to perform well at scale 3. the store is meant to be a quick way to have some visibility of data while testing 4. the store works for both legacy & MD connections
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
import P from "pino"
|
||||
import { Boom } from "@hapi/boom"
|
||||
import makeWASocket, { DisconnectReason, AnyMessageContent, delay, useSingleFileAuthState } from '../src'
|
||||
import makeWASocket, { DisconnectReason, AnyMessageContent, delay, useSingleFileAuthState, makeInMemoryStore } from '../src'
|
||||
|
||||
// the store maintains the data of the WA connection in memory
|
||||
// can be written out to a file & read from it
|
||||
const store = makeInMemoryStore({ logger: P().child({ level: 'debug', stream: 'store' }) })
|
||||
store.readFromFile('./baileys_store.json')
|
||||
|
||||
setInterval(() => {
|
||||
store.writeToFile('./baileys_store.json')
|
||||
}, 10_000)
|
||||
|
||||
const { state, saveState } = useSingleFileAuthState('./auth_info_multi.json')
|
||||
|
||||
@@ -19,6 +28,8 @@ const startSock = () => {
|
||||
}
|
||||
})
|
||||
|
||||
store.bind(sock.ev)
|
||||
|
||||
const sendMessageWTyping = async(msg: AnyMessageContent, jid: string) => {
|
||||
await sock.presenceSubscribe(jid)
|
||||
await delay(500)
|
||||
|
||||
Reference in New Issue
Block a user