whatsapp-bot/src/lib/deduplication.ts
Martin Porwoll 8847358507 feat: initial WhatsApp Business Bot scaffold
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>
2026-03-02 10:58:51 +00:00

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
}
}