From b65b3c6ff015582d6ef2aba721d969b8d87debe6 Mon Sep 17 00:00:00 2001 From: Limitless <127183162+Limitless2023@users.noreply.github.com> Date: Sun, 15 Feb 2026 16:49:10 +0800 Subject: [PATCH] fix(telegram): include voice transcript in body text instead of raw audio (#16789) - Move hasAudio detection before bodyText building - Move preflight transcription before bodyText building - If audio has transcript, use transcript as bodyText - Otherwise use placeholder Fixes #16772: Telegram voice messages leak raw audio binary into chat context Co-authored-by: Limitless2023 --- src/telegram/bot-message-context.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/telegram/bot-message-context.ts b/src/telegram/bot-message-context.ts index 041c93eab..62d6443c5 100644 --- a/src/telegram/bot-message-context.ts +++ b/src/telegram/bot-message-context.ts @@ -396,18 +396,11 @@ export const buildTelegramMessageContext = async ({ } let bodyText = rawBody; - if (!bodyText && allMedia.length > 0) { - bodyText = `${allMedia.length > 1 ? ` (${allMedia.length} images)` : ""}`; - } - const hasAnyMention = (msg.entities ?? msg.caption_entities ?? []).some( - (ent) => ent.type === "mention", - ); - const explicitlyMentioned = botUsername ? hasBotMention(msg, botUsername) : false; + const hasAudio = allMedia.some((media) => media.contentType?.startsWith("audio/")); // Preflight audio transcription for mention detection in groups // This allows voice notes to be checked for mentions before being dropped let preflightTranscript: string | undefined; - const hasAudio = allMedia.some((media) => media.contentType?.startsWith("audio/")); const needsPreflightTranscription = isGroup && requireMention && hasAudio && !hasUserText && mentionRegexes.length > 0; @@ -432,6 +425,20 @@ export const buildTelegramMessageContext = async ({ } } + // Build bodyText - if there's audio with transcript, use transcript; otherwise use placeholder + if (!bodyText && allMedia.length > 0) { + if (hasAudio) { + bodyText = preflightTranscript || ""; + } else { + bodyText = `${allMedia.length > 1 ? ` (${allMedia.length} images)` : ""}`; + } + } + + const hasAnyMention = (msg.entities ?? msg.caption_entities ?? []).some( + (ent) => ent.type === "mention", + ); + const explicitlyMentioned = botUsername ? hasBotMention(msg, botUsername) : false; + const computedWasMentioned = matchesMentionWithExplicit({ text: msg.text ?? msg.caption ?? "", mentionRegexes,