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:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user