Skip to content

fix: clear markdown field when sending media messages via QQ Official Platform#5445

Merged
Soulter merged 2 commits intoAstrBotDevs:masterfrom
KBVsent:fix/qqofficial-media-msg-type-mismatch
Feb 25, 2026
Merged

fix: clear markdown field when sending media messages via QQ Official Platform#5445
Soulter merged 2 commits intoAstrBotDevs:masterfrom
KBVsent:fix/qqofficial-media-msg-type-mismatch

Conversation

@KBVsent
Copy link
Contributor

@KBVsent KBVsent commented Feb 25, 2026

When sends a MessageChain containing both Plain text and Image components via the QQ Official platform (including the webhook), the _post_send method initially sets msg_type=2 with a markdown payload. Upon detecting an image, msg_type is overridden to 7 (rich media), but the markdown field is not cleared. The QQ Official API rejects this mismatched combination with HTTP 500 "msg type not match content", causing the entire message to fail silently.

Modifications / 改动点

  • qqofficial_message_event.py: When msg_type is changed to 7 (for image or record media) in both the GroupMessage and C2CMessage branches, clear the markdown field and move the text into the content field, which is compatible with msg_type=7.
  • This is NOT a breaking change. / 这不是一个破坏性变更。

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


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

错误修复:

  • 当发送包含媒体并设置 msg_type=7 的 QQ 公众号消息时,清除不兼容的 markdown 负载,并将任何文本移入 content 字段中。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Clear incompatible markdown payload when sending QQ Official messages that include media and set msg_type=7, moving any text into the content field instead.

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

Summary of Changes

Hello @KBVsent, 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!

This pull request resolves a critical issue in the QQ Official Platform integration where messages containing both text and media (images or records) would fail due to an incorrect payload structure. The fix ensures that the message payload is correctly formatted for rich media messages, preventing API rejections and allowing mixed-content messages to be sent successfully.

Highlights

  • QQ Official Platform API Error Fix: Addressed an HTTP 500 "msg type not match content" error that occurred when sending messages containing both plain text and images or records via the QQ Official Platform.
  • Message Payload Correction: Ensured that when the message type is updated to 7 (rich media) for images or records, the 'markdown' field is explicitly cleared and any plain text content is moved to the 'content' field, aligning with QQ Official API requirements.
Changelog
  • astrbot/core/platform/sources/qqofficial/qqofficial_message_event.py
    • Cleared the 'markdown' field when 'msg_type' is set to 7 for image media in group messages.
    • Moved 'plain_text' content to the 'content' field when 'msg_type' is set to 7 for image media in group messages.
    • Applied the same logic for record media in group messages, clearing 'markdown' and setting 'content'.
    • Applied the same logic for image media in C2C messages, clearing 'markdown' and setting 'content'.
    • Applied the same logic for record media in C2C messages, clearing 'markdown' and setting 'content'.
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.

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 - 我在这里给出了一些整体性的反馈:

  • 用于切换到 msg_type=7 并相应调整 markdown/content 的逻辑在四个地方重复出现;可以考虑提取一个小的辅助函数(例如 _prepare_media_payload(payload, plain_text)),以减少重复并在未来修改时保持一致性。
  • 与其设置 payload["markdown"] = None,如果 QQ 官方 API 区分缺失字段和空值,完全删除这个键(例如使用 payload.pop("markdown", None)) 可能会更安全。
给 AI Agents 的提示
Please address the comments from this code review:

## Overall Comments
- The logic for switching to `msg_type=7` and adjusting `markdown`/`content` is duplicated in four places; consider extracting a small helper (e.g., `_prepare_media_payload(payload, plain_text)`) to reduce repetition and keep future changes consistent.
- Instead of setting `payload["markdown"] = None`, it may be safer to remove the key entirely (e.g., `payload.pop("markdown", None)`) if the QQ Official API distinguishes between a missing field and a null value.

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

Hey - I've left some high level feedback:

  • The logic for switching to msg_type=7 and adjusting markdown/content is duplicated in four places; consider extracting a small helper (e.g., _prepare_media_payload(payload, plain_text)) to reduce repetition and keep future changes consistent.
  • Instead of setting payload["markdown"] = None, it may be safer to remove the key entirely (e.g., payload.pop("markdown", None)) if the QQ Official API distinguishes between a missing field and a null value.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The logic for switching to `msg_type=7` and adjusting `markdown`/`content` is duplicated in four places; consider extracting a small helper (e.g., `_prepare_media_payload(payload, plain_text)`) to reduce repetition and keep future changes consistent.
- Instead of setting `payload["markdown"] = None`, it may be safer to remove the key entirely (e.g., `payload.pop("markdown", None)`) if the QQ Official API distinguishes between a missing field and a null value.

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 area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. label Feb 25, 2026
@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

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

This pull request correctly addresses the issue of sending media messages on the QQ Official Platform by clearing the markdown field and setting the content field when msg_type is 7. My main feedback is about code duplication. The logic for updating the payload for media messages is repeated four times. I've left a specific comment suggesting a refactor to improve code maintainability.

Comment on lines 165 to 166
payload["markdown"] = None
payload["content"] = plain_text or None
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

These two lines are now repeated in four places within this method (for images/records in both Group and C2C messages). This code duplication can make future maintenance harder. Please consider refactoring to centralize this logic. A possible approach is to determine if any media is present, and if so, apply these payload changes in a single, common block of code.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 25, 2026
@Soulter Soulter merged commit 78660da into AstrBotDevs:master Feb 25, 2026
6 checks passed
KBVsent added a commit to KBVsent/AstrBot that referenced this pull request Feb 25, 2026
… Platform (AstrBotDevs#5445)

* fix: clear markdown field when sending media messages via QQ Official API

* refactor: use pop() to remove markdown key instead of setting None
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:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants