71 lines
2.2 KiB
Python
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 |