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

@@ -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" };
}