OpenWA
OpenWA copied to clipboard
refactor(engine): neutral DeliveryStatus instead of raw whatsapp-web.js ack int (#265)
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 toIWhatsAppEngine;onMessageAcknow delivers aDeliveryStatus, not a raw int. - The wwebjs ack integer is mapped to
DeliveryStatusonly inside the adapter (wwebjsAckToDeliveryStatus). No consumer outside the adapter sees engine ack codes anymore. message-status.util:ackToMessageStatus(int)→deliveryStatusToMessageStatus(status); added deprecateddeliveryStatusToAck(status)to derive the legacy webhookackint. Behaviour is byte-identical for every ack value (verified end-to-end).- Webhook (non-breaking):
message.ack/message.failednow carry a neutralstatus; the legacyackint is kept (deprecated). Idempotency keys preferstatus. - Live ws delivery ticks (bonus fix):
session.servicenow actually emitsmessage.ackover the websocket —emitMessageAckwas previously never called, so the dashboard's live tick path was dead. The dashboard consumes the neutral status string; the integerstatusMap {-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 deprecatedack). - The dead ws delivery-tick path wired live with the neutral status.
PLAYED(4)collapses toread(the DB already did this). Documented deltas: the deprecated webhookackreports3not4for a played receipt, and play-after-read no longer double-firesmessage.ack.
Verification
- Backend build ✅ · 445 tests ✅ (added a
wwebjsAckToDeliveryStatusboundary 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.