fix: clear markdown field when sending media messages via QQ Official Platform#5445
Conversation
Summary of ChangesHello @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
Changelog
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- The logic for switching to
msg_type=7and adjustingmarkdown/contentis 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
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.
| payload["markdown"] = None | ||
| payload["content"] = plain_text or None |
There was a problem hiding this comment.
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.
… 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
When sends a
MessageChaincontaining bothPlaintext andImagecomponents via the QQ Official platform (including the webhook), the_post_sendmethod initially setsmsg_type=2with amarkdownpayload. Upon detecting an image,msg_typeis overridden to7(rich media), but themarkdownfield 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 / 改动点
msg_typeis changed to7(for image or record media) in both theGroupMessageandC2CMessagebranches, clear themarkdownfield and move the text into thecontentfield, which is compatible withmsg_type=7.Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Summary by Sourcery
错误修复:
msg_type=7的 QQ 公众号消息时,清除不兼容的 markdown 负载,并将任何文本移入content字段中。Original summary in English
Summary by Sourcery
Bug Fixes: