feat: implement comprehensive notification engine with policies, preferences, and automated dispatching services

This commit is contained in:
2026-07-21 18:53:11 -03:00
parent 40090cdec5
commit 10ca449f88
82 changed files with 10249 additions and 171 deletions
@@ -0,0 +1,28 @@
const DEFAULT_MIN_INTERVAL_MS = 8000;
const JITTER_MAX_MS = 8000;
export class WhatsAppThrottleClass {
private lastSentAt: Map<string, number> = new Map();
private minIntervalMs: number;
constructor(minIntervalMs: number = DEFAULT_MIN_INTERVAL_MS) {
this.minIntervalMs = minIntervalMs;
}
canSend(companyId: string): boolean {
const lastSent = this.lastSentAt.get(companyId);
if (!lastSent) {
return true;
}
const elapsed = Date.now() - lastSent;
const jitter = Math.floor(Math.random() * JITTER_MAX_MS);
const requiredInterval = this.minIntervalMs + jitter;
return elapsed >= requiredInterval;
}
recordSent(companyId: string): void {
this.lastSentAt.set(companyId, Date.now());
}
}