webhook to site
This commit is contained in:
+9
-1
@@ -19,4 +19,12 @@ APP_TITLE = "Speech Analytics API"
|
||||
APP_VERSION = "1.0.0"
|
||||
|
||||
PORT = int(os.getenv("PORT", "8000"))
|
||||
HOST = os.getenv("HOST", "localhost")
|
||||
HOST = os.getenv("HOST", "localhost")
|
||||
|
||||
# Calls_WEB_Client_main Webhook Configuration
|
||||
CALLS_WEB_CLIENT_URL = os.getenv(
|
||||
"CALLS_WEB_CLIENT_URL",
|
||||
"http://calls_web_client:8000"
|
||||
)
|
||||
WEBHOOK_ENDPOINT = f"{CALLS_WEB_CLIENT_URL}/api/transcription/webhook"
|
||||
WEBHOOK_API_KEY = os.getenv("WEBHOOK_API_KEY", "webhook_secret_key")
|
||||
@@ -10,6 +10,8 @@ from apiApp.database.Audio import Audio
|
||||
from apiApp.database.AiConclusion import AiConclusion
|
||||
from datetime import datetime
|
||||
import logging
|
||||
import requests
|
||||
from apiApp.config import WEBHOOK_ENDPOINT, WEBHOOK_API_KEY
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
ai_conclusion_router = APIRouter()
|
||||
@@ -91,9 +93,42 @@ async def save_ai_conclusion(request: AiConclusionRequest, db: Session = Depends
|
||||
db.commit()
|
||||
logger.info(f"✅ Заключение сохранено для {request.filename}")
|
||||
|
||||
# Отправляем webhook в Calls_WEB_Client_main для анализа
|
||||
try:
|
||||
logger.info(f"📤 Отправка webhook в Calls_WEB_Client_main для {request.filename}")
|
||||
|
||||
webhook_payload = {
|
||||
"audio_id": str(audio.id),
|
||||
"filename": request.filename,
|
||||
"transcription": request.transcription,
|
||||
"corrected_transcription": request.corrected_transcription,
|
||||
"segments": request.segments,
|
||||
"processing_time_seconds": request.processing_time_seconds
|
||||
}
|
||||
|
||||
webhook_response = requests.post(
|
||||
WEBHOOK_ENDPOINT,
|
||||
json=webhook_payload,
|
||||
headers={"X-Webhook-Key": WEBHOOK_API_KEY},
|
||||
timeout=30
|
||||
)
|
||||
|
||||
if webhook_response.status_code == 200:
|
||||
logger.info(f"✅ Webhook успешно отправлен для {request.filename}")
|
||||
else:
|
||||
logger.warning(f"⚠️ Webhook вернул статус {webhook_response.status_code}")
|
||||
logger.warning(f"Response: {webhook_response.text}")
|
||||
|
||||
except requests.exceptions.ConnectionError:
|
||||
logger.error(f"❌ Не удалось подключиться к Calls_WEB_Client_main webhook: {WEBHOOK_ENDPOINT}")
|
||||
except requests.exceptions.Timeout:
|
||||
logger.warning(f"⚠️ Таймаут при отправке webhook для {request.filename}")
|
||||
except Exception as e:
|
||||
logger.error(f"❌ Ошибка при отправке webhook: {e}")
|
||||
|
||||
return AiConclusionResponse(
|
||||
success=True,
|
||||
message='Заключение сохранено',
|
||||
message='Заключение сохранено и отправлено на анализ',
|
||||
audio_id=str(audio.id),
|
||||
filename=request.filename
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user