Skip to content

Fix wecom adapter returning json instead of plain text#9107

Open
Makarov3821 wants to merge 2 commits into
AstrBotDevs:masterfrom
Makarov3821:master
Open

Fix wecom adapter returning json instead of plain text#9107
Makarov3821 wants to merge 2 commits into
AstrBotDevs:masterfrom
Makarov3821:master

Conversation

@Makarov3821

@Makarov3821 Makarov3821 commented Jul 1, 2026

Copy link
Copy Markdown

#9077 的修复,对于企业微信客服的验证返回纯文本而不是json,以避免回调验证失败

Modifications / 改动点

修改了astrbot/core/platform/sources/wecom/wecom_adapter.py和astrbot/dashboard/api/platform.py两处五行,在reponse输出前进行重整。

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

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

image

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

Ensure WeCom platform verification callbacks return the expected plain-text HTTP response instead of JSON-wrapped data.

Bug Fixes:

  • Return WeCom enterprise customer service verification echo strings as a plain-text HTTP response to satisfy the external callback requirements.

Enhancements:

  • Allow the dashboard platform API helper to pass through raw FastAPI Response objects returned by operations instead of always wrapping them in a JSON envelope.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. area:webui The bug / feature is about webui(dashboard) of astrbot. labels Jul 1, 2026

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/platform/sources/wecom/wecom_adapter.py" line_range="120" />
<code_context>
async def handle_verify(self, request) -> str:
</code_context>
<issue_to_address>
**issue:** Return type annotation no longer matches the actual Response return value.

This function is annotated to return `str` but now returns a `FastAPIResponse`, creating a contract mismatch for callers and type checkers. Please update the return annotation (and any related interfaces) to use the appropriate `Response` type so the signature reflects the actual behavior.
</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.

Comment thread astrbot/core/platform/sources/wecom/wecom_adapter.py

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

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.

Code Review

This pull request modifies the WeCom adapter to return a FastAPIResponse instead of a plain string during verification, and updates the dashboard API runner to handle Response objects directly. The review feedback correctly suggests updating the return type annotation of handle_verify to FastAPIResponse to ensure type safety and prevent static analysis errors.

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.

)
logger.info("验证请求有效性成功。")
return echo_str
return FastAPIResponse(content=echo_str, media_type="text/plain")

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

由于 handle_verify 方法现在返回的是 FastAPIResponse 对象,建议将该方法的返回类型标注(位于第 101 行:async def handle_verify(self, request) -> str:)更新为 FastAPIResponse,以保持类型声明的准确性,避免静态类型检查工具(如 mypy 或 pyright)报错。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

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. area:webui The bug / feature is about webui(dashboard) of astrbot. size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant