Commit Graph

15 Commits

Author SHA1 Message Date
maaz519 952a0e9b49 feat: pass JID on connect; extract startAccount() helper; poll 30s for new accounts
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 11:44:54 +05:30
maaz519 02dad1347c feat: thread QR/status callbacks through session pool; persist to DB in main
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 11:08:51 +05:30
maaz519 18edce7552 feat: add onQr/onStatus callbacks to session; auto-restart on loggedOut
Adds OnQrCallback and OnStatusCallback parameters to createWhatsAppSession,
broadcasts QR strings and connection status changes to callers, and clears
session files then restarts automatically when the socket is logged out.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 11:04:39 +05:30
maaz519 d33b4e40b8 fix: use type-only Baileys import and raw status code to fix Jest ESM issue
Replaces DisconnectReason enum import with type-only WASocket import and
uses 401 directly instead of DisconnectReason.loggedOut. Baileys is an ES
module that cannot be executed in Jest's CommonJS mode, so removing the
value import (keeping only type imports) prevents ts-jest from trying to
execute the module.

Also updated session-pool.test.ts to verify end() is called with the
expected Boom error object instead of undefined.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-27 17:40:24 +05:30
maaz519 06449acd96 fix: pass loggedOut reason in closeAll to prevent reconnect timers after shutdown 2026-05-27 17:38:37 +05:30
maaz519 41aabc4c0d fix: address code quality issues in session pool, approval, and main
- session.ts: add onReconnect callback so reconnected socket replaces stale pool entry
- session-pool.ts: pass onReconnect to update pool on reconnect; add closeAll() to gracefully end WebSocket connections on shutdown
- approval.ts: use approved flag so double-approval race (updateMany count=0) returns null instead of sending duplicate forward jobs
- main.ts: wrap pool.add() in try/catch to continue if one account fails; replace silent groupMap fallback with explicit error log and early return; call pool.closeAll() before BullMQ shutdown to prevent hanging sockets
- Tests: add closeAll() test to session-pool.test.ts; add double-approval race test to approval.test.ts (56 tests total, all passing)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-27 17:35:52 +05:30
maaz519 9cdc41e23e fix(worker): improve sendMessage error, add session-pool unit tests 2026-05-27 17:14:56 +05:30
maaz519 0f30af6018 feat(worker): WhatsAppSessionPool + group-sync accepts accountId 2026-05-27 17:11:19 +05:30
maaz519 705bd177e8 fix(worker): reactorJid null guard, document reaction removal, restore comments 2026-05-27 17:03:47 +05:30
maaz519 f255ef91fb feat(worker): seal WhatsApp adapter — normalize inside session, reactions handled internally
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-27 16:58:22 +05:30
maaz519 31f047492a fix: harden session error handling, normalizer null guard, extract redis-connection
- Wrap groupFetchAllParticipating in try/catch to prevent unhandled rejection on connect
- Catch errors from async onMessage/onGroups callbacks via Promise.resolve().catch
- Return null from normalizer when key.id is missing (prevents empty upsert key collision)
- Extract parseRedisUrl to redis-connection.ts to eliminate duplication

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-27 16:18:56 +05:30
maaz519 a4771aaf05 feat: add Baileys WhatsApp session with reconnect logic
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-27 15:33:46 +05:30
maaz519 0d45bd8bd6 feat: add WhatsApp group sync to database
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-27 15:19:15 +05:30
maaz519 7151e0dd6d feat: add Baileys message normalizer
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-27 15:08:10 +05:30
maaz519 4c721f0b19 feat: add tag detector for TOWER message flagging
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-27 15:00:37 +05:30