Skip to content

fix(telegram): cannot send video message (#2536)#5430

Merged
Soulter merged 1 commit intoAstrBotDevs:masterfrom
CCCCCCTV:fix-telegram-video-send
Feb 25, 2026
Merged

fix(telegram): cannot send video message (#2536)#5430
Soulter merged 1 commit intoAstrBotDevs:masterfrom
CCCCCCTV:fix-telegram-video-send

Conversation

@CCCCCCTV
Copy link
Contributor

@CCCCCCTV CCCCCCTV commented Feb 25, 2026

Fixes #2536 修复 Telegram 机器人无法发送视频且日志无明显报错的问题。

Modifications / 改动点

修复 astrbot/core/platform/sources/telegram/tg_event.py 中的视频发送逻辑,
确保视频文件正确传递给 Telegram API,从而解决发送失败但无报错的问题。

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

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ 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.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

在普通发送和流式发送中正确处理 Telegram 视频消息,并修复基于线程的 Telegram 消息回复元数据问题。

Bug 修复:

  • 修复 Telegram 视频消息在常规发送中未被发送的问题,方法是将视频文件正确传递给 Telegram API。
  • 修复 Telegram 视频消息在流式回复期间未被发送的问题,方法是添加正确的 视频上传处理并使用合适的聊天动作(chat action)。
  • 通过在带线程的 Telegram 消息中发送 message_thread_id 而非 reply_to_message_id,纠正线程元数据的使用。
Original summary in English

Summary by Sourcery

Handle Telegram video messages correctly in both normal and streaming sends and fix thread-based reply metadata for Telegram messages.

Bug Fixes:

  • Fix Telegram video messages not being sent by correctly passing video files to the Telegram API in regular sends.
  • Fix Telegram video messages not being sent during streaming replies by adding proper video upload handling with the correct chat action.
  • Correct the use of thread metadata by sending message_thread_id instead of reply_to_message_id for threaded Telegram messages.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 25, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @CCCCCCTV, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在解决 Telegram 机器人无法发送视频且没有明确错误日志的问题。通过增强 Telegram 平台事件处理逻辑,现在可以正确识别和发送视频消息,并修正了消息线程参数的传递方式,从而提升了机器人在 Telegram 平台上的多媒体消息处理能力和稳定性。

Highlights

  • 新增视频消息类型支持: 引入了 Video 消息类型,并在 Telegram 平台事件处理中为其添加了相应的聊天动作 (UPLOAD_VIDEO)。
  • 修复视频发送逻辑: 在 send_with_clientsend_streaming 方法中增加了对 Video 消息的处理,确保视频文件能够正确转换为路径并发送给 Telegram API。
  • 修正消息线程参数: 在 send_streaming 方法中,将用于回复消息线程的参数从 reply_to_message_id 更正为 message_thread_id,以符合 Telegram API 的预期。
Changelog
  • astrbot/core/platform/sources/telegram/tg_event.py
    • 导入了 Video 消息类型。
    • Video 消息类型映射到 ChatAction.UPLOAD_VIDEO
    • send_with_client 函数中增加了视频消息的发送逻辑。
    • send_streaming 函数中修正了消息线程 ID 的参数名称。
    • send_streaming 函数中增加了视频消息的发送逻辑。
Activity
  • 目前没有人工活动记录。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot
Copy link

dosubot bot commented Feb 25, 2026

Related Documentation

Checked 1 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added the area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. label Feb 25, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - 我发现了 1 个问题,并给出了一些整体性的反馈:

  • send_streaming 中,payload 现在已经包含了 message_thread_id,但你在视频分支调用 _send_media_with_action 时又显式传入了 message_thread_id=message_thread_id,这会导致重复的关键字参数;建议在所有使用到它的分支中,要么从 payload 中移除它,要么从显式参数中移除它。
  • send_with_client 中,新的 Video 分支没有转发任何图文说明(与图片分支中使用 caption=i.text or None 不同),所以如果 Video 段可以包含说明文字,你可能也希望把 caption 传给 send_video,以保持一致性。
给 AI Agent 的提示词
Please address the comments from this code review:

## Overall Comments
- In `send_streaming`, `payload` now includes `message_thread_id`, but you also pass `message_thread_id=message_thread_id` explicitly into `_send_media_with_action` for videos, which will cause a duplicate keyword argument; consider removing it from either the payload or the explicit arguments for all branches that use it.
- In `send_with_client`, the new `Video` branch does not forward any caption text (unlike the image branch using `caption=i.text or None`), so if `Video` segments can carry captions you may want to pass `caption` through to `send_video` as well for consistency.

## Individual Comments

### Comment 1
<location path="astrbot/core/platform/sources/telegram/tg_event.py" line_range="421" />
<code_context>
+                            ChatAction.UPLOAD_VIDEO,
+                            self.client.send_video,
+                            user_name=user_name,
+                            message_thread_id=message_thread_id,
+                            video=path,
+                            **cast(Any, payload),
</code_context>
<issue_to_address>
**issue (bug_risk):** Passing message_thread_id both explicitly and via **payload may cause a duplicate keyword error.

Since `payload["message_thread_id"] = message_thread_id` is set earlier in the streaming path, expanding `**payload` here while also passing `message_thread_id` explicitly will raise `TypeError: got multiple values for keyword argument 'message_thread_id'` when `message_thread_id` is truthy. Either drop the explicit argument here or stop adding `message_thread_id` to `payload` when you pass it separately.
</issue_to_address>

Sourcery 对开源项目是免费的——如果你觉得我们的评审对你有帮助,欢迎分享 ✨
帮我变得更有用!请对每条评论点下 👍 或 👎,我会根据你的反馈改进代码评审质量。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • In send_streaming, payload now includes message_thread_id, but you also pass message_thread_id=message_thread_id explicitly into _send_media_with_action for videos, which will cause a duplicate keyword argument; consider removing it from either the payload or the explicit arguments for all branches that use it.
  • In send_with_client, the new Video branch does not forward any caption text (unlike the image branch using caption=i.text or None), so if Video segments can carry captions you may want to pass caption through to send_video as well for consistency.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `send_streaming`, `payload` now includes `message_thread_id`, but you also pass `message_thread_id=message_thread_id` explicitly into `_send_media_with_action` for videos, which will cause a duplicate keyword argument; consider removing it from either the payload or the explicit arguments for all branches that use it.
- In `send_with_client`, the new `Video` branch does not forward any caption text (unlike the image branch using `caption=i.text or None`), so if `Video` segments can carry captions you may want to pass `caption` through to `send_video` as well for consistency.

## Individual Comments

### Comment 1
<location path="astrbot/core/platform/sources/telegram/tg_event.py" line_range="421" />
<code_context>
+                            ChatAction.UPLOAD_VIDEO,
+                            self.client.send_video,
+                            user_name=user_name,
+                            message_thread_id=message_thread_id,
+                            video=path,
+                            **cast(Any, payload),
</code_context>
<issue_to_address>
**issue (bug_risk):** Passing message_thread_id both explicitly and via **payload may cause a duplicate keyword error.

Since `payload["message_thread_id"] = message_thread_id` is set earlier in the streaming path, expanding `**payload` here while also passing `message_thread_id` explicitly will raise `TypeError: got multiple values for keyword argument 'message_thread_id'` when `message_thread_id` is truthy. Either drop the explicit argument here or stop adding `message_thread_id` to `payload` when you pass it separately.
</issue_to_address>

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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 PR 修复了 Telegram 视频发送失败的问题,通过为 Video 消息组件添加专门的处理逻辑来实现。同时,还修正了在话题组(topic group)中流式消息回复的参数错误。

代码改动方向正确,有效解决了视频无法发送的问题。我提出了一些关于视频字幕处理的改进建议,以确保与图片消息的处理方式保持一致,从而提升功能的完整性。

@CCCCCCTV CCCCCCTV force-pushed the fix-telegram-video-send branch from 01a3067 to 84f9273 Compare February 25, 2026 05:03
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Feb 25, 2026
@Soulter Soulter changed the title fix(telegram): 修复视频发送失败且无日志报错的问题 (#2536) fix(telegram): cannot send video message (#2536) Feb 25, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 25, 2026
@Soulter Soulter merged commit 3eb1508 into AstrBotDevs:master Feb 25, 2026
6 checks passed
@CCCCCCTV CCCCCCTV deleted the fix-telegram-video-send branch February 25, 2026 12:30
astrbot-doc-agent bot pushed a commit to AstrBotDevs/AstrBot-docs that referenced this pull request Feb 25, 2026
@astrbot-doc-agent
Copy link

Generated docs update PR (pending manual review):
AstrBotDevs/AstrBot-docs#150
Trigger: PR merged


AI change summary:

  • 更新 zh/deploy/platform/telegram.md,新增“更新日志”章节,说明 v4.15.0+ 修复了视频消息发送失败、流式回复视频处理及话题消息回复元数据等问题。
  • 更新 en/deploy/platform/telegram.md,同步新增“Changelog”章节。
  • 中英文文档已同步更新。

Experimental bot notice:

  • This output is generated by AstrBot-Doc-Agent for review only.
  • It does not represent the final documentation form.

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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]telegram无法收到视频

2 participants