Today we implemented the core Messaging Processing infrastructure for our Node.js chatbot. Leveraging the WhatsApp Webhook model, we came up with a receiver for incoming callbacks, deduplicates messages, marks them as read, and echoes a response—triggering WhatsApp’s “double‑check” (✓✓) receipt experience for the user.
WhatsApp can batch multiple messages (and retries) into a single webhook invocation. Without proper handling:
To address these challenges, we must support ordered processing pipeline that safely handles multiple incoming messages per webhook, ensuring each is processed exactly once and in a predictable sequence.
Authentication (GET)
hub.mode
, hub.verify_token
and hub.challenge
.Incoming Messages (POST)
/whatsapp-webhook
endpoint.200 EVENT_RECEIVED
to prevent retries.messageId
in MongoDB’s ProcessedMessages
.markMessageAsRead()
so user sees ✓✓.defaultHandler
echoes “OK,” completing the acknowledgment cycle.for each entry → for each change → for each message:
if not in ProcessedMessages:
insert message.id
markMessageAsRead(...)
defaultHandler(...)
findOne({ messageId })
prevents re‑processing duplicates.messageId
+ timestamp marks it as handled.After dedupe, we invoke:
await markMessageAsRead(phone_number_id, message.id)
User sees two gray ticks turn blue as soon as our reply is accepted by WhatsApp.
Current implementation simply sends back “OK”:
await sendMessage(pnId, from, 'OK')
This minimal echo confirms our pipeline works end‑to‑end before adding real business logic.
© 2019–2025 Weplex Comunicação. Atendemos presencialmente em Ribeirão Preto, na Maurílio Biagi 800, Sala 1104 (SP) ou remotamente, profissionais liberais de todo Brasil e do mundo.
Meplex Comunicações, Weplex Comunicações, Weplex Communications e xBio são marcas registradas de Weplex Comunicações. Todo o conteúdo deste site está protegido por direitos autorais © 2019–2025 Weplex Comunicações. Todos os direitos reservados.