From ea19be1d06f8ebe50952af7f28b7eb2a63d955de Mon Sep 17 00:00:00 2001 From: Marshall Date: Thu, 2 Jul 2026 23:27:08 +0800 Subject: [PATCH] fix: wecom adapter returning json instead of plain text (#9107) * Fix wecom adapter returning json instead of plain text * Fix handle_verify return class --- astrbot/core/platform/sources/wecom/wecom_adapter.py | 5 +++-- astrbot/dashboard/api/platform.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/astrbot/core/platform/sources/wecom/wecom_adapter.py b/astrbot/core/platform/sources/wecom/wecom_adapter.py index e80b762c2..2cee8c695 100644 --- a/astrbot/core/platform/sources/wecom/wecom_adapter.py +++ b/astrbot/core/platform/sources/wecom/wecom_adapter.py @@ -8,6 +8,7 @@ from pathlib import Path from typing import Any, cast from urllib.parse import unquote +from fastapi.responses import Response as FastAPIResponse from requests import Response from wechatpy.enterprise import WeChatClient, parse_message from wechatpy.enterprise.crypto import WeChatCrypto @@ -97,7 +98,7 @@ class WecomServer: """内部服务器的 GET 验证入口""" return await self.handle_verify(request) - async def handle_verify(self, request) -> str: + async def handle_verify(self, request) -> FastAPIResponse: """处理验证请求,可被统一 webhook 入口复用 Args: @@ -116,7 +117,7 @@ class WecomServer: args.get("echostr"), ) logger.info("验证请求有效性成功。") - return echo_str + return FastAPIResponse(content=echo_str, media_type="text/plain") except InvalidSignatureException: logger.error("验证请求有效性失败,签名异常,请检查配置。") raise diff --git a/astrbot/dashboard/api/platform.py b/astrbot/dashboard/api/platform.py index c6a6f7f55..3ba03d745 100644 --- a/astrbot/dashboard/api/platform.py +++ b/astrbot/dashboard/api/platform.py @@ -3,6 +3,7 @@ from __future__ import annotations from typing import Any from fastapi import APIRouter, Depends, Request +from fastapi.responses import Response from astrbot.dashboard.asgi_runtime import DashboardRequest from astrbot.dashboard.async_utils import run_maybe_async @@ -50,6 +51,8 @@ def _model_dict(payload) -> dict[str, Any]: async def _run(operation): try: result = await run_maybe_async(operation) + if isinstance(result, Response): + return result return ok(result) except PlatformServiceError as exc: _raise_platform_error(exc)