import type Redis from 'ioredis' import { getLogger } from './logger.js' const log = getLogger('deduplication') const DEDUP_TTL = 86400 // 24 hours export class MessageDeduplicator { constructor(private redis: Redis) {} async isDuplicate(messageId: string): Promise { const key = `wa:dedup:${messageId}` const result = await this.redis.set(key, '1', 'EX', DEDUP_TTL, 'NX') if (result === null) { log.warn({ messageId }, 'Duplicate message detected') return true } return false } }