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 <media:audio> placeholder

Fixes #16772: Telegram voice messages leak raw audio binary into chat context

Co-authored-by: Limitless2023 <limitless@users.noreply.github.com>
This commit is contained in:
Limitless
2026-02-15 16:49:10 +08:00
committed by GitHub
parent 229376fbed
commit b65b3c6ff0

View File

@@ -396,18 +396,11 @@ export const buildTelegramMessageContext = async ({
}
let bodyText = rawBody;
if (!bodyText && allMedia.length > 0) {
bodyText = `<media:image>${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 || "<media:audio>";
} else {
bodyText = `<media:image>${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,