Skip to content

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

Merged
Soulter merged 1 commit into
AstrBotDevs:masterfrom
Trainingcqy:fix/telegram-video-note
Aug 12, 2026
Merged

fix: convert Telegram video notes into a Video component#9627
Soulter merged 1 commit into
AstrBotDevs:masterfrom
Trainingcqy:fix/telegram-video-note

Conversation

@Trainingcqy

@Trainingcqy Trainingcqy commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

A Telegram video note, the round clip you record with the shortcut in the Telegram client, never makes it into the pipeline. convert_message() dispatches on message type and the chain of branches stops at video: there is no video_note branch, so nothing matches and AstrBotMessage.message goes out as an empty list. The request is then dropped in agent_sub_stages/internal.py, where has_valid_message, has_media_content and has_reply are all false. The bot stays silent, and nothing further down the pipeline ever learns that a video arrived.

Modifications / 改动点

astrbot/core/platform/sources/telegram/tg_adapter.py:

  • New video_note branch, built like the existing video branch, producing a Comp.Video.

tests/fixtures/helpers.py: create_mock_update() takes a video_note argument.

tests/test_telegram_adapter.py: one new case covering a video note becoming a Comp.Video.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

Before the fix

The video note arrives and parses fine, and the dump shows the video_note field. Nothing is added to the chain, though, and the request is dropped at internal:190 without an error or a warning anywhere. On the client side the message simply looks sent; ask about it and the model says it never got a video.

Log (before)
[16:56:22.857] [Core] [DBUG] [telegram.tg_adapter:427]: Telegram message: Message(channel_chat_created=False, chat=Chat(first_name='<name>', id=<user_id>, type=<ChatType.PRIVATE>), date=datetime.datetime(2026, 8, 11, 7, 56, 22, tzinfo=datetime.timezone.utc), delete_chat_photo=False, from_user=User(first_name='<name>', id=<user_id>, is_bot=False, language_code='zh-hans'), group_chat_created=False, message_id=82, supergroup_chat_created=False, video_note=VideoNote(_duration=datetime.timedelta(seconds=6), api_kwargs={'thumb': {'file_id': 'AAMCBAADGQEAA1JqetWmeXKLymbXDafoJb7WwqoYywADIAAC-W3YU-9ocnOSYCC7AQAHbQADPQQ', 'file_unique_id': 'AQAEIAAC-W3YU3I', 'file_size': 13182, 'width': 320, 'height': 320}}, file_id='DQACAgQAAxkBAANSanrVpnlyi8pm1w2n6CW-1sKqGMsAAyAAAvlt2FPvaHJzkmAguz0E', file_size=682062, file_unique_id='AgAEIAAC-W3YUw', length=384, thumbnail=PhotoSize(file_id='AAMCBAADGQEAA1JqetWmeXKLymbXDafoJb7WwqoYywADIAAC-W3YU-9ocnOSYCC7AQAHbQADPQQ', file_size=13182, file_unique_id='AQAEIAAC-W3YU3I', height=320, width=320)))
[16:56:22.857] [Core] [INFO] [core.event_bus:74]: [default] [telegram(telegram)] Unknown/<user_id>:
[16:56:22.863] [Core] [DBUG] [agent_sub_stages.internal:190]: skip llm request: empty message and no provider_request
[16:56:22.864] [Core] [DBUG] [pipeline.scheduler:95]: pipeline execution completed.
[16:56:44.078] [Core] [INFO] [core.event_bus:74]: [default] [telegram(telegram)] Unknown/<user_id>: 描述视频内容
[16:56:55.130] [Core] [INFO] [respond.stage:206]: Prepare to send - Unknown/<user_id>: 您好!我目前还没有收到您发送的视频文件、视频链接或文件路径。

请通过以下方式之一提供视频:
1. **直接发送/上传视频文件**
2. **发送视频的下载链接或在线播放网址**
3. **提供视频在本地/服务器上的具体文件路径**

收到视频后,我会为您分析并详细描述视频的内容!
修复前截图

After the fix

The video note now produces a Comp.Video, has_media_content is true, and the request goes to the provider like any other video. Asked the same question, the model answers from the file it received.

Log (after)
[17:09:29.361] [Core] [DBUG] [telegram.tg_adapter:427]: Telegram message: Message(channel_chat_created=False, chat=Chat(first_name='<name>', id=<user_id>, type=<ChatType.PRIVATE>), date=datetime.datetime(2026, 8, 11, 8, 9, 29, tzinfo=datetime.timezone.utc), delete_chat_photo=False, from_user=User(first_name='<name>', id=<user_id>, is_bot=False, language_code='zh-hans'), group_chat_created=False, message_id=96, supergroup_chat_created=False, video_note=VideoNote(_duration=datetime.timedelta(seconds=6), api_kwargs={'thumb': {'file_id': 'AAMCBAADGQEAA2Bqeti42EPOE-ZyT5keCSF_7ynNnAACBCAAAvlt2FPQ_dDZ9ZyQRwEAB20AAz0E', 'file_unique_id': 'AQADBCAAAvlt2FNy', 'file_size': 21527, 'width': 320, 'height': 320}}, file_id='DQACAgQAAxkBAANganrYuNhDzhPmck-ZHgkhf-8pzZwAAgQgAAL5bdhT0P3Q2fWckEc9BA', file_size=492412, file_unique_id='AgADBCAAAvlt2FM', length=360, thumbnail=PhotoSize(file_id='AAMCBAADGQEAA2Bqeti42EPOE-ZyT5keCSF_7ynNnAACBCAAAvlt2FPQ_dDZ9ZyQRwEAB20AAz0E', file_size=21527, file_unique_id='AQADBCAAAvlt2FNy', height=320, width=320)))
[17:09:30.791] [Core] [INFO] [core.event_bus:74]: [default] [telegram(telegram)] Unknown/<user_id>: [ComponentType.Video]
[17:09:30.792] [Core] [INFO] [core.event_bus:74]: [default] [telegram(telegram)] Unknown/<user_id>: 描述视频内容
[17:09:30.797] [Core] [DBUG] [agent_sub_stages.internal:193]: ready to request llm provider
[17:10:18.158] [Core] [INFO] [respond.stage:206]: Prepare to send - Unknown/<user_id>: 已收到您发送的视频文件。以下是该视频的基本信息:

- **视频时长**:约 5.78 秒
- **分辨率**:360 × 360
- **帧率**:30 FPS
- **音频轨**:包含 AAC 单声道音频
…
修复后截图

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Handle Telegram video note messages by converting them into standard video components so they flow through the pipeline like other media.

New Features:

  • Support Telegram video notes as video components in the messaging pipeline.

Enhancements:

  • Extend Telegram mock update helper to include video_note messages for use in tests.

Tests:

  • Add a Telegram adapter test ensuring video notes are converted into Comp.Video instances with correct file and path values.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. labels Aug 11, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The new video_note branch duplicates much of the existing video handling; consider extracting a small helper to resolve the file and construct the Comp.Video so both code paths stay consistent and easier to maintain.
  • In the video_note branch you set both file and path to file.file_path; if regular videos use a different URL/Path scheme, it may be safer to reuse the same logic (e.g., using the same helper that builds a public file URL) so video notes behave identically in downstream components.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `video_note` branch duplicates much of the existing `video` handling; consider extracting a small helper to resolve the file and construct the `Comp.Video` so both code paths stay consistent and easier to maintain.
- In the `video_note` branch you set both `file` and `path` to `file.file_path`; if regular videos use a different URL/Path scheme, it may be safer to reuse the same logic (e.g., using the same helper that builds a public file URL) so video notes behave identically in downstream components.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 12, 2026
@Soulter
Soulter merged commit 91ee487 into AstrBotDevs:master Aug 12, 2026
21 checks passed
BegoniaHe added a commit to Xero-Team/AstrBot that referenced this pull request Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants