From 8c17e559132a0037bdd1c58cd4b9ca539ba21f18 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Feb 2026 00:51:49 +0800 Subject: [PATCH] feat: Add Telegram voice message receiving support (#1948) * Initial plan * feat: add Telegram voice message receiving support - Add filters.VOICE to Telegram message handler to capture voice messages - Implement voice message processing in target2yiri converter - Download voice files from Telegram API and convert to base64 - Create platform_message.Voice component with proper mime type and duration - Maintain compatibility with existing text, photo, and command messages Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * chore: format code --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> Co-authored-by: Junyan Qin --- src/langbot/pkg/platform/sources/telegram.py | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/langbot/pkg/platform/sources/telegram.py b/src/langbot/pkg/platform/sources/telegram.py index 79a959fa..d09e80c1 100644 --- a/src/langbot/pkg/platform/sources/telegram.py +++ b/src/langbot/pkg/platform/sources/telegram.py @@ -85,6 +85,26 @@ class TelegramMessageConverter(abstract_platform_adapter.AbstractMessageConverte ) ) + if message.voice: + if message.caption: + message_components.extend(parse_message_text(message.caption)) + + file = await message.voice.get_file() + + file_bytes = None + file_format = message.voice.mime_type or 'audio/ogg' + + async with aiohttp.ClientSession(trust_env=True) as session: + async with session.get(file.file_path) as response: + file_bytes = await response.read() + + message_components.append( + platform_message.Voice( + base64=f'data:{file_format};base64,{base64.b64encode(file_bytes).decode("utf-8")}', + length=message.voice.duration, + ) + ) + return platform_message.MessageChain(message_components) @@ -159,7 +179,9 @@ class TelegramAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter): application = ApplicationBuilder().token(config['token']).build() bot = application.bot - application.add_handler(MessageHandler(filters.TEXT | (filters.COMMAND) | filters.PHOTO, telegram_callback)) + application.add_handler( + MessageHandler(filters.TEXT | (filters.COMMAND) | filters.PHOTO | filters.VOICE, telegram_callback) + ) super().__init__( config=config, logger=logger,