fix: require callable Baileys dispatcher

This commit is contained in:
Frank Yang
2026-04-14 16:07:23 +08:00
parent bce3e41e36
commit e9b635df3d
4 changed files with 16 additions and 12 deletions

View File

@@ -40,7 +40,7 @@ index 0d32dfb4882dfe029ba8804772d7d89404b08e76..73809fcd1d52362aef0c35cb7416c29d
+ // `dispatcher` only works with Dispatcher-compatible implementations,
+ // so only wire it through when the object actually implements
+ // `dispatch`.
+ ...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),
+ ...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),
duplex: 'half',
// Note: custom agents/proxy require undici Agent; omitted here.
signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined

8
pnpm-lock.yaml generated
View File

@@ -29,7 +29,7 @@ packageExtensionsChecksum: sha256-n+P/SQo4Pf+dHYpYn1Y6wL4cJEVoVzZ835N0OEp4TM8=
patchedDependencies:
'@whiskeysockets/baileys@7.0.0-rc.9':
hash: 5a0b2527947a3aabf3c7f11cd6ff61e4ba7b5a2c13516fec4cb275dc63bd0308
hash: 23ec8efe1484afa57c51b96955ba331d1467521a8e676a18c2690da7e70a6201
path: patches/@whiskeysockets__baileys@7.0.0-rc.9.patch
importers:
@@ -119,7 +119,7 @@ importers:
version: 7.15.0
'@whiskeysockets/baileys':
specifier: 7.0.0-rc.9
version: 7.0.0-rc.9(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5)
version: 7.0.0-rc.9(patch_hash=23ec8efe1484afa57c51b96955ba331d1467521a8e676a18c2690da7e70a6201)(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5)
ajv:
specifier: ^8.18.0
version: 8.18.0
@@ -1226,7 +1226,7 @@ importers:
dependencies:
'@whiskeysockets/baileys':
specifier: 7.0.0-rc.9
version: 7.0.0-rc.9(patch_hash=5a0b2527947a3aabf3c7f11cd6ff61e4ba7b5a2c13516fec4cb275dc63bd0308)(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5)
version: 7.0.0-rc.9(patch_hash=23ec8efe1484afa57c51b96955ba331d1467521a8e676a18c2690da7e70a6201)(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5)
jimp:
specifier: ^1.6.1
version: 1.6.1
@@ -11428,7 +11428,7 @@ snapshots:
'@wasm-audio-decoders/common': 9.0.7
optional: true
'@whiskeysockets/baileys@7.0.0-rc.9(patch_hash=5a0b2527947a3aabf3c7f11cd6ff61e4ba7b5a2c13516fec4cb275dc63bd0308)(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5)':
'@whiskeysockets/baileys@7.0.0-rc.9(patch_hash=23ec8efe1484afa57c51b96955ba331d1467521a8e676a18c2690da7e70a6201)(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5)':
dependencies:
'@cacheable/node-cache': 1.7.6
'@hapi/boom': 9.1.4

View File

@@ -94,7 +94,7 @@ const BAILEYS_MEDIA_DISPATCHER_HEADER_REPLACEMENT = [
" // `dispatcher` only works with Dispatcher-compatible implementations,",
" // so only wire it through when the object actually implements",
" // `dispatch`.",
" ...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),",
" ...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),",
].join("\n");
const BAILEYS_MEDIA_ONCE_IMPORT_RE = /import\s+\{\s*once\s*\}\s+from\s+['"]events['"]/u;
const BAILEYS_MEDIA_ASYNC_CONTEXT_RE =
@@ -311,7 +311,11 @@ export function applyBaileysEncryptedStreamFinishHotfix(params = {}) {
applied = true;
}
if (!patchedText.includes("...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),")) {
if (
!patchedText.includes(
"...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),",
)
) {
if (!patchedText.includes(BAILEYS_MEDIA_DISPATCHER_NEEDLE)) {
return { applied: false, reason: "unexpected_content" };
}

View File

@@ -127,7 +127,7 @@ function createBaileysMessagesMediaSource(params?: {
" // `dispatcher` only works with Dispatcher-compatible implementations,",
" // so only wire it through when the object actually implements",
" // `dispatch`.",
" ...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),",
" ...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),",
" duplex: 'half',",
" });",
]
@@ -317,7 +317,7 @@ describe("stageBundledPluginRuntimeDeps", () => {
"await Promise.all([encFinishPromise, originalFinishPromise]);",
);
expect(fs.readFileSync(targetPath, "utf8")).toContain(
"...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),",
"...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),",
);
expect(fs.readFileSync(targetPath, "utf8")).not.toContain("dispatcher: fetchAgent,");
});
@@ -351,7 +351,7 @@ describe("stageBundledPluginRuntimeDeps", () => {
"await Promise.all([encFinishPromise, originalFinishPromise]);",
);
expect(fs.readFileSync(targetPath, "utf8")).toContain(
"...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),",
"...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),",
);
});
@@ -383,7 +383,7 @@ describe("stageBundledPluginRuntimeDeps", () => {
targetPath,
});
expect(fs.readFileSync(targetPath, "utf8")).toContain(
"...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),",
"...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),",
);
expect(fs.readFileSync(targetPath, "utf8")).toContain("await encFinishPromise;");
expect(fs.readFileSync(targetPath, "utf8")).toContain("await originalFinishPromise;");
@@ -417,7 +417,7 @@ describe("stageBundledPluginRuntimeDeps", () => {
expect(fs.readFileSync(targetPath, "utf8")).toContain("await encFinishPromise;");
expect(fs.readFileSync(targetPath, "utf8")).toContain("await originalFinishPromise;");
expect(fs.readFileSync(targetPath, "utf8")).toContain(
"...(fetchAgent?.dispatch ? { dispatcher: fetchAgent } : {}),",
"...(typeof fetchAgent?.dispatch === 'function' ? { dispatcher: fetchAgent } : {}),",
);
});