feat: implement comprehensive notification engine with policies, preferences, and automated dispatching services
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user