Skip to content

fix(qqofficial): use appid self id for incoming messages#8522

Closed
FlanChanXwO wants to merge 1 commit into
AstrBotDevs:masterfrom
FlanChanXwO:codex/qqofficial-appid-at-pollution
Closed

fix(qqofficial): use appid self id for incoming messages#8522
FlanChanXwO wants to merge 1 commit into
AstrBotDevs:masterfrom
FlanChanXwO:codex/qqofficial-appid-at-pollution

Conversation

@FlanChanXwO
Copy link
Copy Markdown

@FlanChanXwO FlanChanXwO commented Jun 2, 2026

Summary

  • pass the QQ official appid into WebSocket and webhook message parsing
  • use appid as self_id so downstream code can resolve bot identity/avatar data consistently
  • only inject the bot At component for group/channel messages and avoid polluting direct/C2C messages
  • strip the channel <@!appid> mention from text content after preserving the structured At component

Relation to existing PR

This is the narrowed replacement for #7289 / #6741. The existing feat/6741 branch is currently conflicting and contains a large amount of unrelated historical changes. The fork branch is protected against force-push, so this PR keeps only the current QQ official appid/self_id/At fix in a clean branch.

Validation

  • ../AstrBot/.venv/bin/python -m pytest tests/test_qqofficial_adapter.py -q
  • ../AstrBot/.venv/bin/ruff check astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py astrbot/core/platform/sources/qqofficial_webhook/qo_webhook_adapter.py tests/test_qqofficial_adapter.py
  • ../AstrBot/.venv/bin/ruff format --check astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py astrbot/core/platform/sources/qqofficial_webhook/qo_webhook_adapter.py tests/test_qqofficial_adapter.py

Duplicate check

Checked open upstream QQ official PRs. #7289 is the previous broad/conflicting version from this fork; other open QQ official PRs target keyboard support, image upload, duplicate consumption, proactive markdown sends, or friend-message send payloads, so no other same-scope PR was found.

Summary by Sourcery

Align QQ Official incoming message parsing with the appid-based bot identity model.

Bug Fixes:

  • Set QQ Official incoming message self_id to the platform appid so downstream identity and avatar resolution work correctly.
  • Avoid injecting bot At mentions into direct/C2C QQ Official messages and strip the raw appid mention from channel text content while preserving structured mentions.

Tests:

  • Add unit tests covering QQ Official WebSocket and webhook handlers, ensuring they pass appid into the parser and validate self_id and At behavior for group, channel, direct, and C2C messages.

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 updates the QQ Official platform adapters to use the configured appid instead of hardcoded strings (like "qq_official" or "unknown_selfid") for identifying the bot (self_id) and when appending At components. It also adds comprehensive unit tests for these changes. A review comment points out a potential runtime crash if appid is configured as an integer, suggesting to coerce it to a string inside _parse_from_qqofficial to ensure robustness.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +537 to 539
appid: str,
) -> AstrBotMessage:
abm = AstrBotMessage()
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.

high

If the user configures appid as an integer in the configuration file (e.g., appid: 123456 in YAML), appid will be passed as an int. This will cause a TypeError when performing string concatenation (e.g., "<@!" + appid + ">") in channel/direct message parsing, leading to a runtime crash.

Coercing appid to a string at the beginning of _parse_from_qqofficial ensures robustness against different configuration types.

Suggested change
appid: str,
) -> AstrBotMessage:
abm = AstrBotMessage()
appid: str,
) -> AstrBotMessage:
appid = str(appid)
abm = AstrBotMessage()

@FlanChanXwO FlanChanXwO closed this Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant