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

71 lines
2.2 KiB
Python

from __future__ import annotations
import logging
from yuxi.channel.extensions.feishu.client import get_client, get_chat_info, get_chat_members, get_user_info
logger = logging.getLogger(__name__)
async def list_peers(account: dict) -> list[dict]:
return []
async def get_group_info(account: dict, chat_id: str) -> dict | None:
app_id = account.get("app_id", "")
app_secret = account.get("app_secret", "")
domain = account.get("domain", "feishu")
http_timeout_ms = account.get("http_timeout_ms", 30000)
if not app_id or not app_secret:
return None
try:
client = get_client(app_id, app_secret, domain, http_timeout_ms)
return await get_chat_info(client, chat_id)
except Exception:
logger.debug("Failed to get group info for %s", chat_id, exc_info=True)
return None
async def list_group_members(
account: dict,
chat_id: str,
*,
page_token: str = "",
page_size: int = 100,
) -> dict:
app_id = account.get("app_id", "")
app_secret = account.get("app_secret", "")
domain = account.get("domain", "feishu")
http_timeout_ms = account.get("http_timeout_ms", 30000)
if not app_id or not app_secret:
return {"members": [], "page_token": "", "has_more": False}
try:
client = get_client(app_id, app_secret, domain, http_timeout_ms)
return await get_chat_members(client, chat_id, page_token, page_size)
except Exception:
logger.debug("Failed to list group members for %s", chat_id, exc_info=True)
return {"members": [], "page_token": "", "has_more": False}
async def resolve_user_info(
account: dict,
user_id: str,
) -> dict | None:
app_id = account.get("app_id", "")
app_secret = account.get("app_secret", "")
domain = account.get("domain", "feishu")
http_timeout_ms = account.get("http_timeout_ms", 30000)
if not app_id or not app_secret:
return None
try:
client = get_client(app_id, app_secret, domain, http_timeout_ms)
return await get_user_info(client, user_id)
except Exception:
logger.debug("Failed to resolve user info for %s", user_id, exc_info=True)
return None