mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 21:54:32 +00:00
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:
@@ -396,18 +396,11 @@ export const buildTelegramMessageContext = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
let bodyText = rawBody;
|
let bodyText = rawBody;
|
||||||
if (!bodyText && allMedia.length > 0) {
|
const hasAudio = allMedia.some((media) => media.contentType?.startsWith("audio/"));
|
||||||
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;
|
|
||||||
|
|
||||||
// Preflight audio transcription for mention detection in groups
|
// Preflight audio transcription for mention detection in groups
|
||||||
// This allows voice notes to be checked for mentions before being dropped
|
// This allows voice notes to be checked for mentions before being dropped
|
||||||
let preflightTranscript: string | undefined;
|
let preflightTranscript: string | undefined;
|
||||||
const hasAudio = allMedia.some((media) => media.contentType?.startsWith("audio/"));
|
|
||||||
const needsPreflightTranscription =
|
const needsPreflightTranscription =
|
||||||
isGroup && requireMention && hasAudio && !hasUserText && mentionRegexes.length > 0;
|
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({
|
const computedWasMentioned = matchesMentionWithExplicit({
|
||||||
text: msg.text ?? msg.caption ?? "",
|
text: msg.text ?? msg.caption ?? "",
|
||||||
mentionRegexes,
|
mentionRegexes,
|
||||||
|
|||||||
Reference in New Issue
Block a user