From d53de5b12253a0576cb098d1a5dbb2558973d2dc Mon Sep 17 00:00:00 2001 From: Wahyu Saputra Date: Thu, 11 Dec 2025 12:25:40 +0700 Subject: [PATCH 1/4] fix: patch Baileys to filter sender from senderKeyJids in LID groups Baileys v6.7.19 includes sender's own devices in senderKeyJids when sending to LID-addressed groups, causing WhatsApp to reject with 'not-acceptable' error. This patch filters sender's own devices from the senderKeyJids list before sending group messages, following the same pattern Baileys uses for non-group messages (meJids vs otherJids filtering). Changes: - Add Baileys patch in patches/baileys+6.7.19+lid-group-send.patch - Update Dockerfile to apply patch after npm ci - Extract meUser from meId and meLid from authState.creds - Skip sender's own devices in senderKeyJids loop Fixes: #issue-number Related: WhiskeySockets/Baileys#1690, #1768 --- CHANGELOG.md | 2 +- Dockerfile | 4 ++++ patches/baileys+6.7.19+lid-group-send.patch | 22 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 patches/baileys+6.7.19+lid-group-send.patch diff --git a/CHANGELOG.md b/CHANGELOG.md index 3449ad1ba..936e5ac8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Widget Works Modification -* [WIDGET-WORKS] Silence "Parent message not found" warnings during history sync to prevent CPU overload and subsequent 401 disconnects. +* [WIDGET-WORKS] Patch Baileys to filter sender's own devices from senderKeyJids in LID group messages (fixes "not-acceptable" error preventing group message sends). * [WIDGET-WORKS] Fix `PrismaClientValidationError` in `messages.update` (missing `Message` relation) by guarding `messageUpdate.create` calls. * [WIDGET-WORKS] Guard `messages.update` cache cleanup with a derived key and optional `MESSAGE_UPDATE_CACHE_DELETE_DISABLED` flag to prevent cache.delete crash-loops. * [WIDGET-WORKS] Save messages before Chatwoot sync in `/message/sendText` to avoid missing `chatwootMessageId` and log async sync failures. diff --git a/Dockerfile b/Dockerfile index 2f30eea09..b46d34d36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,10 @@ COPY ./tsup.config.ts ./ RUN npm ci --silent +# [WIDGET-WORKS] Apply Baileys patch for LID group send fix +COPY ./patches ./patches +RUN patch -p0 < patches/baileys+6.7.19+lid-group-send.patch || echo "Patch already applied or failed" + COPY ./src ./src COPY ./public ./public COPY ./prisma ./prisma diff --git a/patches/baileys+6.7.19+lid-group-send.patch b/patches/baileys+6.7.19+lid-group-send.patch new file mode 100644 index 000000000..e3e29d7f1 --- /dev/null +++ b/patches/baileys+6.7.19+lid-group-send.patch @@ -0,0 +1,22 @@ +diff --git a/node_modules/baileys/lib/Socket/messages-send.js b/node_modules/baileys/lib/Socket/messages-send.js +index 1234567..abcdefg 100644 +--- a/node_modules/baileys/lib/Socket/messages-send.js ++++ b/node_modules/baileys/lib/Socket/messages-send.js +@@ -360,8 +360,14 @@ export const makeMessagesSocket = (config) => { + meId + }); + const senderKeyJids = []; +- // ensure a connection is established with every device ++ // [WIDGET-WORKS] Filter sender's own devices from senderKeyJids (LID group send fix) ++ // Same pattern as non-group path (line ~396) - fixes "not-acceptable" error ++ const { user: meUser } = jidDecode(meId); ++ const meLid = authState.creds?.me?.lid?.split(':')[0]?.split('@')[0]; ++ // ensure a connection is established with every device + for (const { user, device } of devices) { ++ // [WIDGET-WORKS] Skip sender's own devices ++ if (user === meUser || user === meLid) { ++ continue; ++ } + const jid = jidEncode(user, groupData?.addressingMode === 'lid' ? 'lid' : 's.whatsapp.net', device); + if (!senderKeyMap[jid] || !!participant) { + senderKeyJids.push(jid); From 38b013764a1741ca0448a436f31b74ae0803d06e Mon Sep 17 00:00:00 2001 From: Wahyu Saputra Date: Thu, 11 Dec 2025 12:55:55 +0700 Subject: [PATCH 2/4] fix(docker): install patch binary in Alpine for Baileys patch application Alpine Linux does not include 'patch' by default. Without this, the Baileys LID group send patch would silently fail during build, leaving the fix unapplied in production images. Changes: - Add 'patch' to apk install list - Remove '|| echo' fallback to fail fast on patch errors --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b46d34d36..2369f31b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM node:20-alpine AS builder RUN apk update && \ - apk add --no-cache git ffmpeg wget curl bash openssl + apk add --no-cache git ffmpeg wget curl bash openssl patch LABEL version="2.3.2" description="Api to control whatsapp features through http requests." LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes" @@ -17,7 +17,7 @@ RUN npm ci --silent # [WIDGET-WORKS] Apply Baileys patch for LID group send fix COPY ./patches ./patches -RUN patch -p0 < patches/baileys+6.7.19+lid-group-send.patch || echo "Patch already applied or failed" +RUN patch -p0 < patches/baileys+6.7.19+lid-group-send.patch COPY ./src ./src COPY ./public ./public From ea6b54d6dfea8fdf5bac5945448fab8748b62c85 Mon Sep 17 00:00:00 2001 From: Wahyu Saputra Date: Thu, 11 Dec 2025 13:02:31 +0700 Subject: [PATCH 3/4] Fix patch strip level for Baileys LID group fix --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2369f31b0..28e04b249 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN npm ci --silent # [WIDGET-WORKS] Apply Baileys patch for LID group send fix COPY ./patches ./patches -RUN patch -p0 < patches/baileys+6.7.19+lid-group-send.patch +RUN patch -p1 < patches/baileys+6.7.19+lid-group-send.patch COPY ./src ./src COPY ./public ./public From b1c030c3c72ebab18bc5cdfd6ed251a6c88e305b Mon Sep 17 00:00:00 2001 From: Wahyu Saputra Date: Thu, 11 Dec 2025 13:13:30 +0700 Subject: [PATCH 4/4] fix(patch): correct patch format and strip level - Use unified diff format without git headers - Change from -p1 to -p0 for correct path stripping - Ensures patch applies correctly during Docker build --- Dockerfile | 2 +- patches/baileys+6.7.19+lid-group-send.patch | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 28e04b249..2369f31b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN npm ci --silent # [WIDGET-WORKS] Apply Baileys patch for LID group send fix COPY ./patches ./patches -RUN patch -p1 < patches/baileys+6.7.19+lid-group-send.patch +RUN patch -p0 < patches/baileys+6.7.19+lid-group-send.patch COPY ./src ./src COPY ./public ./public diff --git a/patches/baileys+6.7.19+lid-group-send.patch b/patches/baileys+6.7.19+lid-group-send.patch index e3e29d7f1..5584e773c 100644 --- a/patches/baileys+6.7.19+lid-group-send.patch +++ b/patches/baileys+6.7.19+lid-group-send.patch @@ -1,8 +1,6 @@ -diff --git a/node_modules/baileys/lib/Socket/messages-send.js b/node_modules/baileys/lib/Socket/messages-send.js -index 1234567..abcdefg 100644 --- a/node_modules/baileys/lib/Socket/messages-send.js +++ b/node_modules/baileys/lib/Socket/messages-send.js -@@ -360,8 +360,14 @@ export const makeMessagesSocket = (config) => { +@@ -360,8 +360,14 @@ meId }); const senderKeyJids = [];