A fully featured in-memory state manager designed as a drop-in replacement
for the deprecated makeInMemoryStore from the latest versions of Baileys
(WhatsApp Web API library).
Built specifically for WhatsApp Multi-Device bots using the modern event-driven architecture.
The original makeInMemoryStore was removed from newer versions of Baileys.
Many bots still rely on it for:
- Contact caching
- Chat indexing
- Message history tracking
- Presence updates
- Group metadata storage
- Call state tracking
- Auth state syncing
This module restores that functionality β with improvements and modern safeguards.
setContacts()upsertContact()updateContact()deleteContact()
setChats()upsertChat()updateChat()deleteChat()
setMessages()upsertMessage()updateMessage()deleteMessage()loadMessage()
Supports:
- Poll updates
- Message merges (preserves old data)
- Optional per-chat message limit (memory safeguard)
- Event emission compatibility
setPresence()updatePresence()
Tracks per-chat and per-participant presence state.
setGroupMetadata()updateGroupMetadata()
setCallOffer()clearCallOffer()
setStickerPacks()upsertStickerPack()
setAuthState()getAuthState()
markHistorySynced()isHistorySynced()
load(state)save()clear()
bind(ev)unbind(ev)(optional safety cleanup)
Fully compatible with Baileys socket event emitter.
This store:
- Extends
EventEmitter - Maintains internal indexed objects for fast lookup
- Emits events similar to Baileys
- Supports manual persistence
- Includes safe guards & validation
- Optionally limits message cache per chat
- Works with modern Baileys socket events
This is an in-memory store.
All data is lost when the process restarts unless you manually persist it.
Install recommended logger:
npm install pinoThen copy store.js into your project.
// Require file
const makeInMemoryStore = require('./store')
const pino = require('pino')
// Create store
const store = makeInMemoryStore({
logger: pino({ level: 'silent' }),
maxMessagesPerChat: 500 // optional
})const sock = makeWASocket({ ... })
store.bind(sock.ev)Once bound, the store will automatically update itself when:
- Contacts change
- Messages arrive
- Groups update
- Presence updates
- Call events fire
- History sync completes
No manual syncing required.
If your socket reconnects or reloads, you may safely call:
store.unbind(sock.ev)before re-binding to prevent duplicate listeners.
Since this is memory-only, you can persist it manually.
const fs = require('fs')
setInterval(() => {
const state = store.save()
fs.writeFileSync('./store.json', JSON.stringify(state))
}, 10000)if (fs.existsSync('./store.json')) {
const data = JSON.parse(fs.readFileSync('./store.json'))
store.load(data)
}store.contacts
store.upsertContact(contact)
store.deleteContact([id])store.chats
store.upsertChat(chat)
store.deleteChat([id])store.messages
store.loadMessage(jid, messageId)
store.upsertMessage(message)store.presences
store.setPresence(chatId, presence)store.groupMetadatastore.getAuthState()If you are running a large-scale bot:
- Persist store regularly
- Consider limiting stored messages per chat
- Monitor memory usage
- Use proper logging levels (pino supported)
For heavy production bots, you may consider migrating to:
- Redis
- MongoDB
- PostgreSQL
For smallβmedium bots, this store is extremely fast and efficient.
β
Development
β
Testing
β
Lightweight bots
β
Temporary session bots
- O(1) object access
- Fast message lookup
- No disk I/O overhead
- Fully event-driven
- Minimal dependencies
- Optional in-memory safeguards for long-running processes
Designed for:
- Latest Multi-Device Baileys versions
- Node.js 16+
Maxz
https://linktr.ee/dcodemaxz
Custom implementation inspired by deprecated Baileys store system.
Free for personal and commercial use.