mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-27 07:54:19 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -68,6 +68,7 @@ class BotService:
|
|||||||
'wecomcs',
|
'wecomcs',
|
||||||
'LINE',
|
'LINE',
|
||||||
'lark',
|
'lark',
|
||||||
|
'gewechat',
|
||||||
]:
|
]:
|
||||||
webhook_prefix = self.ap.instance_config.data['api'].get('webhook_prefix', 'http://127.0.0.1:5300')
|
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', '')
|
extra_webhook_prefix = self.ap.instance_config.data['api'].get('extra_webhook_prefix', '')
|
||||||
|
|||||||
@@ -404,11 +404,7 @@ class GewechatEventConverter(abstract_platform_adapter.AbstractEventConverter):
|
|||||||
class GeWeChatAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter):
|
class GeWeChatAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter):
|
||||||
bot: gewechat_client.GewechatClient = None
|
bot: gewechat_client.GewechatClient = None
|
||||||
bot_uuid: str = None
|
bot_uuid: str = None
|
||||||
|
webhook_url: str = None
|
||||||
bot_account_id: str = ''
|
|
||||||
|
|
||||||
config: dict
|
|
||||||
|
|
||||||
message_converter: GewechatMessageConverter = None
|
message_converter: GewechatMessageConverter = None
|
||||||
event_converter: GewechatEventConverter = None
|
event_converter: GewechatEventConverter = None
|
||||||
|
|
||||||
@@ -418,8 +414,6 @@ class GeWeChatAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter):
|
|||||||
] = {}
|
] = {}
|
||||||
|
|
||||||
def __init__(self, config: dict, logger: EventLogger):
|
def __init__(self, config: dict, logger: EventLogger):
|
||||||
self.config = config
|
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
config=config,
|
config=config,
|
||||||
logger=logger,
|
logger=logger,
|
||||||
@@ -431,6 +425,9 @@ class GeWeChatAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter):
|
|||||||
def set_bot_uuid(self, bot_uuid: str):
|
def set_bot_uuid(self, bot_uuid: str):
|
||||||
self.bot_uuid = bot_uuid
|
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):
|
async def handle_unified_webhook(self, bot_uuid: str, path: str, request):
|
||||||
data = await request.json
|
data = await request.json
|
||||||
await self.logger.debug(f'Gewechat callback event: {data}')
|
await self.logger.debug(f'Gewechat callback event: {data}')
|
||||||
@@ -578,8 +575,9 @@ class GeWeChatAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def _build_callback_url(self) -> str:
|
def _build_callback_url(self) -> str:
|
||||||
base_url = self.config.get('callback_base_url', '').rstrip('/')
|
if self.webhook_url:
|
||||||
return f'{base_url}/api/bots/{self.bot_uuid}'
|
return self.webhook_url
|
||||||
|
raise Exception('webhook_url 未设置,请检查 LangBot 的 api.webhook_prefix 配置')
|
||||||
|
|
||||||
async def run_async(self):
|
async def run_async(self):
|
||||||
if not self.config['token']:
|
if not self.config['token']:
|
||||||
|
|||||||
@@ -31,16 +31,6 @@ spec:
|
|||||||
type: string
|
type: string
|
||||||
required: true
|
required: true
|
||||||
default: ""
|
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
|
- name: app_id
|
||||||
label:
|
label:
|
||||||
en_US: App ID
|
en_US: App ID
|
||||||
|
|||||||
Reference in New Issue
Block a user