fix: convert Telegram video notes into a Video component (#9627)

This commit is contained in:
Trainingcqy
2026-08-12 11:27:03 +09:00
committed by GitHub
parent dbc0e7113f
commit 91ee487131
3 changed files with 37 additions and 0 deletions
@@ -637,6 +637,17 @@ class TelegramPlatformAdapter(Platform):
message.message.append(Comp.Video(file=file_path, path=file.file_path))
_apply_caption()
elif update.message.video_note:
# Video notes carry no file_name and cannot have a caption.
file = await update.message.video_note.get_file()
file_path = file.file_path
if file_path is None:
logger.warning(
"Telegram video note file_path is None, cannot save the file.",
)
else:
message.message.append(Comp.Video(file=file_path, path=file_path))
return message
async def handle_media_group_message(
+3
View File
@@ -99,6 +99,7 @@ def create_mock_update(
document: MagicMock | None = None,
voice: MagicMock | None = None,
sticker: MagicMock | None = None,
video_note: MagicMock | None = None,
reply_to_message: MagicMock | None = None,
quote: MagicMock | None = None,
caption: str | None = None,
@@ -122,6 +123,7 @@ def create_mock_update(
document: 文档对象
voice: 语音对象
sticker: 贴纸对象
video_note: 圆形视频消息对象
reply_to_message: 回复的消息
quote: 回复消息中的部分引用
caption: 说明文字
@@ -159,6 +161,7 @@ def create_mock_update(
message.document = document
message.voice = voice
message.sticker = sticker
message.video_note = video_note
message.reply_to_message = reply_to_message
message.quote = quote
message.caption = caption
+23
View File
@@ -287,6 +287,29 @@ async def test_telegram_animated_sticker_without_thumbnail_skips_image():
assert result.message_str == "Sticker: 🙄"
@pytest.mark.asyncio
async def test_telegram_video_note_becomes_video_component():
TelegramPlatformAdapter = _load_telegram_adapter()
adapter = TelegramPlatformAdapter(
make_platform_config("telegram"),
{},
asyncio.Queue(),
)
file_path = "https://api.telegram.org/file/test/note.mp4"
update = create_mock_update(
message_text=None,
video_note=create_mock_file(file_path),
)
result = await adapter.convert_message(update, _build_context())
assert result is not None
assert len(result.message) == 1
assert isinstance(result.message[0], Comp.Video)
assert result.message[0].file == file_path
assert result.message[0].path == file_path
@pytest.mark.asyncio
async def test_telegram_voice_message_creates_record_component(tmp_path):
TelegramPlatformAdapter = _load_telegram_adapter()