feat: thread QR/status callbacks through session pool; persist to DB in main

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-29 11:08:51 +05:30
parent 18edce7552
commit 02dad1347c
3 changed files with 45 additions and 0 deletions
+22
View File
@@ -122,6 +122,28 @@ async function bootstrap() {
const map = await syncGroups(groups, accountId, prisma);
groupMaps.set(accountId, map);
},
async (qr, accountId) => {
await prisma.account.update({
where: { id: accountId },
data: { qrCode: qr },
}).catch((err) => logger.error({ accountId, err }, 'Failed to store QR in DB'));
logger.info({ accountId }, 'QR code updated');
},
async (status, accountId) => {
if (status === 'connected') {
await prisma.account.update({
where: { id: accountId },
data: { qrCode: null, status: 'ACTIVE' },
}).catch((err) => logger.error({ accountId, err }, 'Failed to update account status'));
logger.info({ accountId }, 'Account connected — QR cleared');
} else if (status === 'logged_out') {
await prisma.account.update({
where: { id: accountId },
data: { status: 'DISCONNECTED' },
}).catch((err) => logger.error({ accountId, err }, 'Failed to update account status'));
logger.info({ accountId }, 'Account logged out — awaiting QR scan');
}
},
);
} catch (err) {
logger.error({ accountId: account.id, err }, 'Failed to start session — skipping account');