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>
39 lines
942 B
JSON
39 lines
942 B
JSON
{
|
|
"name": "@cmbot/bot",
|
|
"version": "0.1.0",
|
|
"private": true,
|
|
"type": "module",
|
|
"main": "./dist/index.js",
|
|
"scripts": {
|
|
"build": "tsc -p tsconfig.json",
|
|
"dev": "tsx watch src/index.ts",
|
|
"start": "node dist/index.js",
|
|
"test": "vitest run",
|
|
"lint": "echo 'lint placeholder'",
|
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
},
|
|
"dependencies": {
|
|
"@cmbot/db": "workspace:*",
|
|
"@cmbot/shared": "workspace:*",
|
|
"@whiskeysockets/baileys": "7.0.0-rc10",
|
|
"drizzle-orm": "^0.36.0",
|
|
"luxon": "^3.5.0",
|
|
"p-limit": "^7.3.0",
|
|
"pg": "^8.13.0",
|
|
"pg-boss": "^12.18.2",
|
|
"pino": "^9.5.0",
|
|
"pino-pretty": "^11.3.0",
|
|
"qrcode": "^1.5.4",
|
|
"zod": "^3.23.8"
|
|
},
|
|
"devDependencies": {
|
|
"@types/luxon": "^3.4.2",
|
|
"@types/node": "^22.7.0",
|
|
"@types/pg": "^8.11.10",
|
|
"@types/qrcode": "^1.5.5",
|
|
"tsx": "^4.19.0",
|
|
"typescript": "^5.5.0",
|
|
"vitest": "^2.1.0"
|
|
}
|
|
}
|