fix(gateway): avoid duplicate Telegram text after auto-TTS voice replies

This commit is contained in:
Zyrixtrex 2026-05-16 07:36:08 +03:00 committed by Teknium
parent b46ef2ef7a
commit f8eeb570cb
2 changed files with 121 additions and 3 deletions

View file

@ -3187,13 +3187,25 @@ class BasePlatformAdapter(ABC):
logger.warning("[%s] Auto-TTS failed: %s", self.name, tts_err)
# Play TTS audio before text (voice-first experience)
_tts_caption_delivered = False
if _tts_path and Path(_tts_path).exists():
try:
await self.play_tts(
telegram_tts_caption = None
if (
self.platform == Platform.TELEGRAM
and text_content
and text_content[:1024] == text_content
):
telegram_tts_caption = text_content
tts_result = await self.play_tts(
chat_id=event.source.chat_id,
audio_path=_tts_path,
caption=telegram_tts_caption,
metadata=_thread_metadata,
)
_tts_caption_delivered = bool(
telegram_tts_caption and getattr(tts_result, "success", False)
)
finally:
try:
os.remove(_tts_path)
@ -3201,7 +3213,7 @@ class BasePlatformAdapter(ABC):
pass
# Send the text portion
if text_content:
if text_content and not _tts_caption_delivered:
logger.info("[%s] Sending response (%d chars) to %s", self.name, len(text_content), event.source.chat_id)
_reply_anchor = _reply_anchor_for_event(event)
# Mark final response messages for notification delivery.