Skip to content

feat(qqofficial): split message chain by media and update sending logic#8376

Merged
Soulter merged 2 commits into
masterfrom
fix/8210
May 27, 2026
Merged

feat(qqofficial): split message chain by media and update sending logic#8376
Soulter merged 2 commits into
masterfrom
fix/8210

Conversation

@Soulter
Copy link
Copy Markdown
Member

@Soulter Soulter commented May 27, 2026

fixes: #8210

Modifications / 改动点

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

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


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

Update QQ Official message sending to split message chains by media elements and adjust sending behavior accordingly.

New Features:

  • Support sending QQ Official message chains as multiple messages when they contain multiple media components.

Enhancements:

  • Refine QQ Official streaming degrade logic to treat all media types as non-streamable and send them via normal requests.
  • Reuse the message chain splitting logic in the QQ Official platform adapter to ensure only one media attachment is included per outgoing message.

Tests:

  • Add unit tests to verify message chain splitting keeps at most one media component per chunk while preserving metadata.
  • Add integration-style tests to ensure multiple file messages are uploaded and sent as separate QQ Official messages.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. labels May 27, 2026
@Soulter Soulter merged commit 7f94bce into master May 27, 2026
20 checks passed
Copy link
Copy Markdown
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 introduces message chain splitting by media type for the QQ Official platform adapter, ensuring that each message chunk contains at most one media component (Image, Record, Video, or File). This is handled in both QQOfficialMessageEvent and QQOfficialPlatformAdapter, with accompanying unit tests. The review feedback points out that the use_markdown_ attribute of the original MessageChain is not preserved when creating the split chunks, and suggests refactoring the chunk creation into a helper function to ensure all necessary attributes are copied correctly.

Comment on lines +195 to +215
chunks.append(
MessageChain(
chain=current_chain,
use_t2i_=message.use_t2i_,
type=message.type,
)
)
current_chain = []
current_has_media = False

current_chain.append(component)
current_has_media = current_has_media or is_media

if current_chain or not message.chain:
chunks.append(
MessageChain(
chain=current_chain,
use_t2i_=message.use_t2i_,
type=message.type,
)
)
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.

medium

In _split_message_chain_by_media, when splitting the message chain, the use_markdown_ attribute of the original MessageChain is not copied to the new chunks. To avoid code duplication when creating these chunks in multiple places, please refactor the chunk creation logic into a shared helper function that copies all necessary attributes (like use_markdown_). Also, remember to update _post_send_one (line 293) to use message_to_send instead of self.send_buffer when retrieving use_markdown_ to keep it self-contained.

def create_chunk(current_chain):
    chunk = MessageChain(
        chain=current_chain,
        use_t2i_=message.use_t2i_,
        type=message.type,
    )
    if hasattr(message, "use_markdown_"):
        chunk.use_markdown_ = message.use_markdown_
    return chunk
References
  1. When implementing similar functionality for different cases, refactor the logic into a shared helper function to avoid code duplication.

Copy link
Copy Markdown
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 - I've left some high level feedback:

  • In _post_send, streaming is disabled for all chunks whenever the message is split (via stream_for_chain = stream if len(message_chains) == 1 else None); if the intent is to stream text-only parts even when media is present later, consider deciding stream per chunk based on whether that chunk contains media.
  • In _post_send_one, the guard if not message_to_send: depends on MessageChain's truthiness semantics; if the actual intent is to skip empty chains, it would be more explicit and robust to check if not message_to_send.chain: instead.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `_post_send`, streaming is disabled for all chunks whenever the message is split (via `stream_for_chain = stream if len(message_chains) == 1 else None`); if the intent is to stream text-only parts even when media is present later, consider deciding `stream` per chunk based on whether that chunk contains media.
- In `_post_send_one`, the guard `if not message_to_send:` depends on `MessageChain`'s truthiness semantics; if the actual intent is to skip empty chains, it would be more explicit and robust to check `if not message_to_send.chain:` instead.

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.

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. 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] QQ官方机器人一次性发送多个文件时实际只发出了第一个文件

1 participant