ForcePilot/backend/package/yuxi/channels/adapters/feishu/commands.py
Kris a6fa7245e5 feat(feishu): 完整实现飞书适配器核心模块
新增飞书机器人适配器全套功能,包括:
- 基础适配器入口与工具导出
- 消息格式化、卡片渲染、回复调度逻辑
- 会话ID生成、模型覆盖策略
- 消息发送缓存、顺序队列管理
- 飞书签名验证、加解密webhook请求
- 审批权限校验、机器人菜单事件处理
- 文档评论、钉消息、语音转码处理
- 静态/动态目录管理、子代理生命周期管理
- 各类工具集:聊天、云盘、文档、知识库API封装
2026-05-12 00:43:59 +08:00

50 lines
1.4 KiB
Python

from __future__ import annotations
from typing import Any
from yuxi.channels.models import ChannelMessage, ChatType, EventType
from yuxi.utils.logging_config import logger
def parse_bot_menu_event(event: dict[str, Any]) -> dict[str, Any] | None:
event_data = event.get("event", {})
event_key = event_data.get("event_key", "")
if not event_key:
logger.debug("[FeishuCmd] No event_key in bot menu event")
return None
timestamp = event_data.get("timestamp", "")
operator = event_data.get("operator", {}) or {}
open_id = operator.get("open_id", "")
return {
"command": event_key,
"open_id": open_id,
"timestamp": timestamp,
}
def build_synthetic_message(
channel_id: str,
channel_type: Any,
open_id: str,
chat_id: str,
command: str,
) -> ChannelMessage:
from yuxi.channels.models import ChannelIdentity, MessageType
return ChannelMessage(
identity=ChannelIdentity(
channel_id=channel_id,
channel_type=channel_type,
channel_user_id=open_id,
channel_chat_id=chat_id,
channel_message_id=f"cmd:{command}",
),
event_type=EventType.BOT_MENU,
message_type=MessageType.TEXT,
chat_type=ChatType.DIRECT,
content=f"/{command}",
metadata={"source": "bot_menu", "command": command},
)