Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): declare Node >=20.19 floor for ESM baileys; doc + test hardening from final review
rmyndharis2ac3f2bb6fc5
diff --git a/.env.example b/.env.exampleindex 57a478661..fccd2da8f 100644--- a/.env.example+++ b/.env.example@@ -74,6 +74,7 @@ PUPPETEER_ARGS=--no-sandbox,--disable-setuid-sandbox,--disable-dev-shm-usage,--d# WWEBJS_WEB_VERSION=2.3000.1023204257# Baileys engine (used when ENGINE_TYPE=baileys). WebSocket client, no Chromium.+# NOTE: the Baileys engine dependency is ESM-only; OpenWA therefore requires Node >= 20.19 (require-of-ESM support).BAILEYS_AUTH_DIR=./data/baileys# NOTE: proxy (PROXY_URL/PROXY_TYPE) is not yet supported by the baileys engine; it is ignored.diff --git a/CHANGELOG.md b/CHANGELOG.mdindex cbfaaf068..d3dc52f16 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,7 +16,6 @@ plugins instead of in core (#265).### Added-- **Baileys engine (minimal slice)** — `ENGINE_TYPE=baileys` now selects a second, browser-free WhatsApp engine built on `@whiskeysockets/baileys` (WebSocket/Noise protocol, no Chromium). This first slice supports linking (QR + pairing code), sending and receiving **text**, recipient resolution, and typing presence; all other operations return HTTP 501 until later slices add a message store. Config: `BAILEYS_AUTH_DIR` (default `./data/baileys`). Proxy is not yet supported on this engine. (#PR)- **Plugin capability layer (Tier-2 extension plugins):** scoped `ctx.messages` (`sendText` / `reply`,routed through `MessageService` so persistence and the send pipeline are preserved) and read-only`ctx.engine` (`getGroupInfo` / `getContacts` / `getContactById` / `checkNumberExists` / `getChats`) on@@ -28,9 +27,11 @@ plugins instead of in core (#265).documented as out of scope for now). (#294)- **`auto-reply` reference extension plugin**, first-party and **registered disabled by default** — enableit via `POST /plugins/auto-reply/enable` to exercise the capability layer end-to-end. (#294)+- **Baileys engine (minimal slice)** — `ENGINE_TYPE=baileys` now selects a second, browser-free WhatsApp engine built on `@whiskeysockets/baileys` (WebSocket/Noise protocol, no Chromium). This first slice supports linking (QR + pairing code), sending and receiving **text**, recipient resolution, and typing presence; all other operations return HTTP 501 until later slices add a message store. Config: `BAILEYS_AUTH_DIR` (default `./data/baileys`). Proxy is not yet supported on this engine. (#PR)### Changed+- ⚠️ **Node.js ≥ 20.19 now required.** The Baileys engine dependency (`@whiskeysockets/baileys`) is ESM-only and is loaded at startup, so OpenWA now requires Node ≥ 20.19 (for `require()` of ESM). Operators on older Node must upgrade. (#PR)- Engine config is now **opaque per-engine**: `EngineFactory` passes only engine-neutral fields(`sessionId`/`proxyUrl`/`proxyType`) to an engine plugin and supplies engine-specific config (Puppeteerfor whatsapp-web.js) as a blob via the plugin context, so a non-browser engine can be added without thediff --git a/package.json b/package.jsonindex 21029a8a3..9ed46369b 100644--- a/package.json+++ b/package.json@@ -1,6 +1,9 @@{"name": "openwa","version": "0.2.10",+ "engines": {+ "node": ">=20.19.0"+ },"description": "Open Source WhatsApp API Gateway - Free, Self-Hosted HTTP API for WhatsApp","author": "Yudhi Armyndharis & OpenWA Contributors","private": true,diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.tsindex 7a3c0bf68..3d3777ecb 100644--- a/src/engine/adapters/baileys.adapter.spec.ts+++ b/src/engine/adapters/baileys.adapter.spec.ts@@ -186,6 +186,9 @@ describe('BaileysAdapter messaging', () => {const adapter = newAdapter();await adapter.initialize({});await expect(adapter.sendTextMessage('x', 'y')).rejects.toBeInstanceOf(EngineNotReadyError);+ await expect(adapter.checkNumberExists('628111')).rejects.toBeInstanceOf(EngineNotReadyError);+ await expect(adapter.getNumberId('628111')).rejects.toBeInstanceOf(EngineNotReadyError);+ await expect(adapter.sendChatState('[email protected]', 'typing')).rejects.toBeInstanceOf(EngineNotReadyError);});});diff --git a/src/engine/adapters/baileys.adapter.ts b/src/engine/adapters/baileys.adapter.tsindex 9e5d9aca5..49274d321 100644--- a/src/engine/adapters/baileys.adapter.ts+++ b/src/engine/adapters/baileys.adapter.ts@@ -425,7 +425,7 @@ export class BaileysAdapter implements IWhatsAppEngine {continue; // protocol/empty messages carry no neutral content}const incoming = this.mapMessage(msg);- if (msg.key.fromMe) {+ if (msg.key.fromMe === true) {this.callbacks.onMessageCreate?.(incoming);} else {this.callbacks.onMessage?.(incoming);diff --git a/test/__mocks__/@whiskeysockets/baileys.ts b/test/__mocks__/@whiskeysockets/baileys.tsindex ccce46980..16dc8b0e9 100644--- a/test/__mocks__/@whiskeysockets/baileys.ts+++ b/test/__mocks__/@whiskeysockets/baileys.ts@@ -3,6 +3,11 @@* ts-jest runs in CommonJS mode; this stub prevents "Cannot use import statement outside a module"* when any source file importing baileys is pulled into the unit test graph.* The e2e boot gate uses jest.mock() inline instead (test/baileys-engine.e2e-spec.ts).+ *+ * Note: the jest moduleNameMapper also redirects the `@whiskeysockets/baileys/(.*)` subpath+ * (including `/package.json`) to this stub, so BaileysPlugin.getEngineLibrary() returns an+ * undefined version in unit tests by design. Production reads the real package.json via the+ * unmapped require.*/export default jest.fn();export const useMultiFileAuthState = jest.fn();