From 1a3ef217d90f7325bb4e0aebe71e099237cbc971 Mon Sep 17 00:00:00 2001 From: fdc310 <2213070223@qq.com> Date: Sun, 22 Mar 2026 05:52:50 +0800 Subject: [PATCH] fix: resolve pydantic init error and auto-generate webhook callback URL - Fix AttributeError by removing self.config assignment before super().__init__() - Remove callback_base_url from adapter config (no longer needed) - Add set_webhook_url() method, called by botmgr with auto-built URL - Add gewechat to webhook URL display list in bot.py - botmgr now passes webhook_prefix + bot_uuid to adapters via set_webhook_url() Co-Authored-By: Claude Opus 4.6 --- src/langbot/pkg/api/http/service/bot.py | 1 + src/langbot/pkg/platform/sources/gewechat.py | 16 +++++++--------- src/langbot/pkg/platform/sources/gewechat.yaml | 10 ---------- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/langbot/pkg/api/http/service/bot.py b/src/langbot/pkg/api/http/service/bot.py index 332c8ec7..fb08f096 100644 --- a/src/langbot/pkg/api/http/service/bot.py +++ b/src/langbot/pkg/api/http/service/bot.py @@ -68,6 +68,7 @@ class BotService: 'wecomcs', 'LINE', 'lark', + 'gewechat', ]: webhook_prefix = self.ap.instance_config.data['api'].get('webhook_prefix', 'http://127.0.0.1:5300') extra_webhook_prefix = self.ap.instance_config.data['api'].get('extra_webhook_prefix', '') diff --git a/src/langbot/pkg/platform/sources/gewechat.py b/src/langbot/pkg/platform/sources/gewechat.py index a99a046b..85dec11e 100644 --- a/src/langbot/pkg/platform/sources/gewechat.py +++ b/src/langbot/pkg/platform/sources/gewechat.py @@ -404,11 +404,7 @@ class GewechatEventConverter(abstract_platform_adapter.AbstractEventConverter): class GeWeChatAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter): bot: gewechat_client.GewechatClient = None bot_uuid: str = None - - bot_account_id: str = '' - - config: dict - + webhook_url: str = None message_converter: GewechatMessageConverter = None event_converter: GewechatEventConverter = None @@ -418,8 +414,6 @@ class GeWeChatAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter): ] = {} def __init__(self, config: dict, logger: EventLogger): - self.config = config - super().__init__( config=config, logger=logger, @@ -431,6 +425,9 @@ class GeWeChatAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter): def set_bot_uuid(self, bot_uuid: str): self.bot_uuid = bot_uuid + def set_webhook_url(self, webhook_url: str): + self.webhook_url = webhook_url + async def handle_unified_webhook(self, bot_uuid: str, path: str, request): data = await request.json await self.logger.debug(f'Gewechat callback event: {data}') @@ -578,8 +575,9 @@ class GeWeChatAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter): pass def _build_callback_url(self) -> str: - base_url = self.config.get('callback_base_url', '').rstrip('/') - return f'{base_url}/api/bots/{self.bot_uuid}' + if self.webhook_url: + return self.webhook_url + raise Exception('webhook_url 未设置,请检查 LangBot 的 api.webhook_prefix 配置') async def run_async(self): if not self.config['token']: diff --git a/src/langbot/pkg/platform/sources/gewechat.yaml b/src/langbot/pkg/platform/sources/gewechat.yaml index 2d0f664f..53446e6d 100644 --- a/src/langbot/pkg/platform/sources/gewechat.yaml +++ b/src/langbot/pkg/platform/sources/gewechat.yaml @@ -31,16 +31,6 @@ spec: type: string required: true default: "" - - name: callback_base_url - label: - en_US: Callback Base URL - zh_Hans: 回调基础URL - description: - en_US: "LangBot public base URL for webhook callbacks, e.g. http://your-server:5300. The full callback URL will be auto-generated as {callback_base_url}/api/bots/{bot_uuid}" - zh_Hans: "LangBot 对外可访问的基础URL,如 http://your-server:5300。完整回调地址将自动生成为 {callback_base_url}/api/bots/{bot_uuid}" - type: string - required: true - default: "" - name: app_id label: en_US: App ID