refactor: 移除审批和回写功能模块 移除了整个审批(approvals)和官方回写(writebacks)功能模块, 包括相关模型、路由、服务和配置项。更新了数据库迁移文件, 删除了相关的审批请求表和官方回写运行表。同时从API路由器中 移除了相应的路由,并调整了安全常量和字段验证器以匹配变更。 ```
86 lines
2.5 KiB
Python
86 lines
2.5 KiB
Python
from fastapi import APIRouter, Depends, Request
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database import get_db
|
|
from app.core.security import ApiPrincipal, require_api_key
|
|
from app.modules.feishu.commands import FeishuCommandService
|
|
from app.modules.feishu.constants import FeishuEventSource, FeishuPayloadKey, FeishuResponseKey
|
|
from app.modules.feishu.events import FeishuEventService
|
|
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()
|
|
return FeishuEventService(db).handle_event(
|
|
payload,
|
|
source=FeishuEventSource.WEBHOOK,
|
|
auto_reply=True,
|
|
)
|
|
|
|
|
|
@router.post("/send-text", response_model=FeishuSendResult)
|
|
def send_text(
|
|
payload: FeishuTextMessage,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
result = FeishuService(db).send_text(
|
|
payload.text,
|
|
receive_id=payload.receive_id,
|
|
receive_id_type=payload.receive_id_type,
|
|
actor=principal.actor,
|
|
)
|
|
return {
|
|
FeishuResponseKey.OK: result.get(FeishuPayloadKey.CODE) == 0,
|
|
FeishuResponseKey.PROVIDER_RESPONSE: result,
|
|
}
|
|
|
|
|
|
@router.post("/send-card", response_model=FeishuSendResult)
|
|
def send_card(
|
|
payload: FeishuCardMessage,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
result = FeishuService(db).send_card(
|
|
payload.card,
|
|
receive_id=payload.receive_id,
|
|
receive_id_type=payload.receive_id_type,
|
|
actor=principal.actor,
|
|
)
|
|
return {
|
|
FeishuResponseKey.OK: result.get(FeishuPayloadKey.CODE) == 0,
|
|
FeishuResponseKey.PROVIDER_RESPONSE: result,
|
|
}
|
|
|
|
|
|
@router.post(
|
|
"/commands/preview",
|
|
response_model=FeishuCommandResult,
|
|
)
|
|
def preview_command(
|
|
payload: FeishuCommandRequest,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
"""Preview local Feishu command routing without requiring webhook delivery."""
|
|
|
|
return FeishuCommandService(db).handle_text(
|
|
payload.text,
|
|
chat_id=payload.chat_id,
|
|
actor=principal.actor,
|
|
auto_reply=payload.auto_reply,
|
|
)
|