ForcePilot/backend/package/yuxi/channel/extensions/feishu/tools/scopes.py
Kris 5e91bb9985 feat(feishu): 新增飞书渠道完整插件实现
新增飞书渠道插件,包含基础配置、事件处理、消息收发、工具调用、权限管理等完整功能模块,支持WebSocket长连接、卡片消息、流式响应、群管理、审批通知等能力
2026-05-21 10:46:42 +08:00

57 lines
1.6 KiB
Python

from __future__ import annotations
import logging
from yuxi.channel.extensions.feishu.client import get_client
logger = logging.getLogger(__name__)
FEISHU_SCOPES_TOOLS = [
{
"name": "feishu_scopes_check",
"description": "检查飞书应用的权限范围",
"parameters": {},
},
]
REQUIRED_SCOPES = [
"im:message",
"im:message:send_as_bot",
"im:chat",
"im:chat:readonly",
"contact:user:readonly",
"contact:user.id:readonly",
]
async def check_scopes(
app_id: str,
app_secret: str,
domain: str,
http_timeout_ms: int = 30000,
) -> dict:
try:
client = get_client(app_id, app_secret, domain, http_timeout_ms)
import lark_oapi
req = lark_oapi.auth.v3.GetAppAccessTokenInternalRequest(
request_body=lark_oapi.auth.v3.GetAppAccessTokenInternalRequestBody(
app_id=app_id,
app_secret=app_secret,
),
)
resp = await client.auth.v3.app_access_token.internal_async(req)
if resp.success() and resp.data:
return {
"success": True,
"message": "Application authentication is working correctly",
"required_scopes": REQUIRED_SCOPES,
}
else:
return {"success": False, "error": getattr(resp, "msg", "")}
except ImportError:
return {"success": False, "error": "lark-oapi SDK not installed"}
except Exception:
logger.exception("Feishu check_scopes error")
return {"success": False, "error": "Internal error"}