39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from yuxi.channel.extensions.feishu.client import get_client, get_user_info
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def resolve_sender_name(
|
|
app_id: str,
|
|
app_secret: str,
|
|
domain: str,
|
|
open_id: str,
|
|
http_timeout_ms: int = 30000,
|
|
) -> str:
|
|
if not open_id:
|
|
return "Unknown"
|
|
|
|
try:
|
|
client = get_client(app_id, app_secret, domain, http_timeout_ms)
|
|
user_info = await get_user_info(client, open_id)
|
|
if user_info and user_info.get("name"):
|
|
return user_info["name"]
|
|
except Exception:
|
|
logger.debug("Failed to resolve sender name for open_id %s", open_id, exc_info=True)
|
|
|
|
return open_id
|
|
|
|
|
|
async def resolve_bot_open_id(client) -> str:
|
|
try:
|
|
resp = await client.im.v1.bot_info.get_async()
|
|
if resp.success() and resp.data:
|
|
bot = getattr(resp.data, "bot", {}) or {}
|
|
return getattr(bot, "open_id", "") if hasattr(bot, "open_id") else ""
|
|
except Exception:
|
|
logger.debug("Failed to resolve bot open_id", exc_info=True)
|
|
return "" |