7 Commits

Author SHA1 Message Date
c9a7e6f089 feat(bot): cross-account parallel + same-account serial fan-out
Replaces the single-threaded, 1.5s-sleep-per-part loop with a
concurrency model that:

* Wraps inner work in PerKeyMutex(accountId) so two reminders on the
  SAME account take turns (running them concurrently would double the
  effective send rate and risk a WhatsApp ban). Different accounts run
  in parallel.
* Bumps pg-boss localConcurrency to BOT_FIRE_CONCURRENCY (default 8),
  so up to 8 different-account reminders can fire simultaneously.
* Bulk-loads groups + media in 2 queries (drops ~3000 round-trips to
  ~3 for a 1000-group run) and pre-creates run_target rows so the
  Activity tab shows progress mid-run.
* Pre-uploads each unique media via MediaUploadCache (one
  generateWAMessageContent call per mediaId, then relayMessage to
  every group). For 1000 groups × 5 MB image, this turns 5 GB of
  upload into 5 MB.
* Runs BOT_GROUP_CONCURRENCY (default 3) groups in parallel within
  one account; parts within a group stay serial so chat order is
  preserved.
* Gates every send on a per-account TokenBucket
  (BOT_MAX_SEND_PER_MINUTE, default 40).
* Replaces the rigid 1.5s inter-part sleep with 200..499 ms jitter.

Adds a unit test verifying accountMutex.run is called keyed by
accountId for active reminders, and skipped for inactive / missing.

Window enforcement, paused/resume, and ETA preview are deferred to
later phases.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 14:44:23 +08:00
21e8e5b582 feat(bot): remove Telegram code; switch to IPC consumer
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 22:37:49 +08:00
abcf19b71a feat(bot): add IPC notify helper + command consumer skeleton 2026-05-09 22:31:40 +08:00
1aef3e969c feat(reminders): add time-parsing + CRUD helpers 2026-05-09 17:22:00 +08:00
113adc7edf feat(scheduler): add pg-boss client + lifecycle
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 17:19:01 +08:00
83d9bf6e9b fix(bot): upgrade Baileys 6.17.16 → 7.0.0-rc10 for protocol compatibility
The 6.17.x line was returning 406 not-acceptable from WhatsApp's pre-key
endpoint when distributing sender keys to per-device JIDs (e.g.
40471728529510:18@s.whatsapp.net). This blocked every group send
regardless of group size.

Baileys 7.0.0-rc series tracks WhatsApp's current protocol. API is
drop-in compatible — typecheck clean, no source changes needed.

Re-pair required: 6.x signal session files are not portable to 7.x.
2026-05-09 17:01:47 +08:00
4a790b9a60 feat(bot): scaffold env, logger, db, health, shutdown
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 16:10:37 +08:00