mirror of
https://github.com/complexcaresolutions/whatsapp-bot.git
synced 2026-03-17 15:04:07 +00:00
Phase 1 implementation with all core modules: - Fastify webhook server with Meta signature validation - WhatsApp Cloud API client (send text/template/interactive, mark as read) - LLM abstraction layer with Claude provider (Haiku for speed) - BullMQ message processing pipeline (dedup, rate limiting) - Bot routing (MessageRouter, ConversationManager, EscalationManager) - Payload CMS integration (InteractionWriter via direct DB, RulesLoader, TemplateResolver) - Healthcare-safe system prompt with medical keyword detection - PM2 ecosystem config Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
20 lines
532 B
TypeScript
20 lines
532 B
TypeScript
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<boolean> {
|
|
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
|
|
}
|
|
}
|