新增飞书机器人适配器全套功能,包括: - 基础适配器入口与工具导出 - 消息格式化、卡片渲染、回复调度逻辑 - 会话ID生成、模型覆盖策略 - 消息发送缓存、顺序队列管理 - 飞书签名验证、加解密webhook请求 - 审批权限校验、机器人菜单事件处理 - 文档评论、钉消息、语音转码处理 - 静态/动态目录管理、子代理生命周期管理 - 各类工具集:聊天、云盘、文档、知识库API封装
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def fetch_app_owner_open_id(client: Any) -> str | None:
|
|
try:
|
|
resp = await client.bot.v3.info()
|
|
if not resp.success():
|
|
logger.warning("[FeishuAppOwner] Failed to fetch bot info: %s", resp.msg)
|
|
return None
|
|
|
|
bot_info = resp.data if hasattr(resp, "data") else {}
|
|
app_owner_open_id = getattr(bot_info, "app_owner_open_id", "") or bot_info.get("app_owner_open_id", "")
|
|
if app_owner_open_id:
|
|
logger.info("[FeishuAppOwner] App owner open_id: %s...", app_owner_open_id[:8])
|
|
return app_owner_open_id
|
|
|
|
logger.warning("[FeishuAppOwner] No app_owner_open_id in bot info response")
|
|
return None
|
|
except Exception as e:
|
|
logger.warning("[FeishuAppOwner] fetch_app_owner_open_id failed: %s", e)
|
|
return None
|
|
|
|
|
|
async def resolve_app_owner_open_id(client: Any, config: dict[str, Any]) -> str:
|
|
explicit = config.get("docOwnerOpenId", "") or config.get("app_owner_open_id", "")
|
|
if explicit:
|
|
return explicit
|
|
|
|
fetched = await fetch_app_owner_open_id(client)
|
|
if fetched:
|
|
return fetched
|
|
|
|
logger.warning("[FeishuAppOwner] Could not resolve app owner open_id, using bot_open_id fallback")
|
|
return config.get("bot_open_id", "")
|