OpenWA icon indicating copy to clipboard operation
OpenWA copied to clipboard

refactor(engine): neutral DeliveryStatus instead of raw whatsapp-web.js ack int (#265)

Open rmyndharis opened this issue 5 months ago • 0 comments

First item of the #265 engine-pluggability decoupling: stop the whatsapp-web.js MessageAck integer from leaking past the engine adapter.

What changed

  • Neutral DeliveryStatus (pending|sent|delivered|read|failed) added to IWhatsAppEngine; onMessageAck now delivers a DeliveryStatus, not a raw int.
  • The wwebjs ack integer is mapped to DeliveryStatus only inside the adapter (wwebjsAckToDeliveryStatus). No consumer outside the adapter sees engine ack codes anymore.
  • message-status.util: ackToMessageStatus(int) → deliveryStatusToMessageStatus(status); added deprecated deliveryStatusToAck(status) to derive the legacy webhook ack int. Behaviour is byte-identical for every ack value (verified end-to-end).
  • Webhook (non-breaking): message.ack/message.failed now carry a neutral status; the legacy ack int is kept (deprecated). Idempotency keys prefer status.
  • Live ws delivery ticks (bonus fix): session.service now actually emits message.ack over the websocket — emitMessageAck was previously never called, so the dashboard's live tick path was dead. The dashboard consumes the neutral status string; the integer statusMap {-1..4} is removed.

A Baileys/other engine adapter now only needs to map its native delivery codes to DeliveryStatus.

Decisions (confirmed with maintainer)

  • Webhook kept non-breaking (add status, keep deprecated ack).
  • The dead ws delivery-tick path wired live with the neutral status.
  • PLAYED(4) collapses to read (the DB already did this). Documented deltas: the deprecated webhook ack reports 3 not 4 for a played receipt, and play-after-read no longer double-fires message.ack.

Verification

  • Backend build ✅ · 445 tests ✅ (added a wwebjsAckToDeliveryStatus boundary test regression-locking the int→status map incl. PLAYED→read) · lint ✅ · dashboard build + lint ✅.
  • Adversarial review (3 dimensions, each independently verified): all hold — exact behavior preservation, type-sound live ws path, no remaining raw-ack leak outside the adapter.

Part of #265.

rmyndharis avatar Jun 16 '26 16:06 rmyndharis