diff --git a/whatsapp-gateway/baileys-client.js b/whatsapp-gateway/baileys-client.js index f6a74d7..a6d0bc9 100644 --- a/whatsapp-gateway/baileys-client.js +++ b/whatsapp-gateway/baileys-client.js @@ -668,9 +668,16 @@ async function checkContact(session_key, phone) { } async function exportChatHistory(session_key) { - const store = sessionStores.get(session_key); + let store = sessionStores.get(session_key); if (!store) { - throw new Error(`No store found for session ${session_key}`); + const storeFile = path.join(SESSIONS_DIR, `${session_key}_store.json`); + if (fs.existsSync(storeFile)) { + store = makeInMemoryStore(); + store.readFromFile(storeFile); + console.log(`[Store] Loaded store from file for ${session_key} (Export)`); + } else { + throw new Error(`No store found for session ${session_key}`); + } } const chats = store.chats.all();