```
feat: 添加公司AI管理平台基础架构 添加了完整的FastAPI后端项目结构,包括: - 环境配置文件(.env.example)和项目说明文档(README.md、AGENTS.md) - Dockerfile用于容器化部署 - 核心基础设施:配置管理、数据库连接、调度器、安全认证 - 模块化设计:AI代理、审批流程、审计日志、业务台账等功能模块 - 支持多数据库连接(主库和遗留系统只读库) - AI适配器支持OpenClaw、Hermes、OpenAI兼容接口 - 飞书集成、报表生成、风险监控等企业级功能 - 完整的依赖管理和测试指南 ```
This commit is contained in:
83
app/modules/feishu/routes.py
Normal file
83
app/modules/feishu/routes.py
Normal file
@@ -0,0 +1,83 @@
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.core.security import require_api_key
|
||||
from app.modules.audit.schemas import AuditLogCreate
|
||||
from app.modules.feishu.commands import FeishuCommandService
|
||||
from app.modules.feishu.schemas import (
|
||||
FeishuCardMessage,
|
||||
FeishuCommandRequest,
|
||||
FeishuCommandResult,
|
||||
FeishuSendResult,
|
||||
FeishuTextMessage,
|
||||
)
|
||||
from app.modules.feishu.service import FeishuService
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/webhook")
|
||||
async def feishu_webhook(request: Request, db: Session = Depends(get_db)) -> dict:
|
||||
"""Handle Feishu webhook challenge and text command events."""
|
||||
|
||||
payload = await request.json()
|
||||
service = FeishuService(db)
|
||||
service.verify_event(payload)
|
||||
if payload.get("challenge"):
|
||||
return {"challenge": payload["challenge"]}
|
||||
service.audit.log(
|
||||
AuditLogCreate(
|
||||
actor="feishu",
|
||||
source="feishu",
|
||||
action="webhook_event",
|
||||
request_payload=payload,
|
||||
response_payload={"accepted": True},
|
||||
)
|
||||
)
|
||||
command = FeishuCommandService(db).extract_event_command(payload)
|
||||
if not command:
|
||||
return {"ok": True, "handled": False}
|
||||
result = FeishuCommandService(db).handle_text(
|
||||
command["text"],
|
||||
chat_id=command["chat_id"],
|
||||
actor=command["actor"],
|
||||
auto_reply=True,
|
||||
)
|
||||
return {"ok": True, "handled": True, "result": result}
|
||||
|
||||
|
||||
@router.post("/send-text", response_model=FeishuSendResult, dependencies=[Depends(require_api_key)])
|
||||
def send_text(payload: FeishuTextMessage, db: Session = Depends(get_db)) -> dict:
|
||||
result = FeishuService(db).send_text(
|
||||
payload.text,
|
||||
receive_id=payload.receive_id,
|
||||
receive_id_type=payload.receive_id_type,
|
||||
)
|
||||
return {"ok": result.get("code") == 0, "provider_response": result}
|
||||
|
||||
|
||||
@router.post("/send-card", response_model=FeishuSendResult, dependencies=[Depends(require_api_key)])
|
||||
def send_card(payload: FeishuCardMessage, db: Session = Depends(get_db)) -> dict:
|
||||
result = FeishuService(db).send_card(
|
||||
payload.card,
|
||||
receive_id=payload.receive_id,
|
||||
receive_id_type=payload.receive_id_type,
|
||||
)
|
||||
return {"ok": result.get("code") == 0, "provider_response": result}
|
||||
|
||||
|
||||
@router.post(
|
||||
"/commands/preview",
|
||||
response_model=FeishuCommandResult,
|
||||
dependencies=[Depends(require_api_key)],
|
||||
)
|
||||
def preview_command(payload: FeishuCommandRequest, db: Session = Depends(get_db)) -> dict:
|
||||
"""Preview local Feishu command routing without requiring webhook delivery."""
|
||||
|
||||
return FeishuCommandService(db).handle_text(
|
||||
payload.text,
|
||||
chat_id=payload.chat_id,
|
||||
actor=payload.actor,
|
||||
auto_reply=payload.auto_reply,
|
||||
)
|
||||
Reference in New Issue
Block a user