Files
ai-talk-callback/app/routes.py
2025-12-08 13:37:04 +08:00

47 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from fastapi import APIRouter, Request, Body, HTTPException, Depends, Path
from sqlalchemy.ext.asyncio import AsyncSession
from app.database import get_db
from app.models import CallbackResponse
from app.config import settings
from app.logger import get_routes_logger
from app.callback_service import log_callback_request
logger = get_routes_logger()
router = APIRouter()
@router.post("/ai-talk/callback/{siteId}/failure", response_model=CallbackResponse)
async def ai_talk_callback(
request: Request,
callback_data: dict = Body(...),
siteId: str = Path(..., description="站点ID"),
db: AsyncSession = Depends(get_db)
):
"""
AI Talk回调接口处理
"""
try:
# 记录回调请求(包含siteId)
success = await log_callback_request(db, request, siteId, callback_data)
if not success:
logger.error("❌ 回调请求日志保存失败")
raise HTTPException(status_code=500, detail="回调请求日志保存失败")
# 立即返回成功响应
return CallbackResponse(
success=True,
message="成功",
processed=False,
retry_count=0,
site_id=siteId
)
except HTTPException:
raise
except Exception as e:
logger.error(f"💥 服务器内部错误: {e}", exc_info=True)
raise HTTPException(
status_code=500,
detail=f"服务器内部错误: {str(e)}"
)