File size: 2,701 Bytes
795dc3a
 
 
893ff0d
795dc3a
 
893ff0d
 
 
795dc3a
 
 
 
 
893ff0d
795dc3a
 
 
 
893ff0d
795dc3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
893ff0d
795dc3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from fastapi import APIRouter, HTTPException, Depends
from pydantic import BaseModel, Field
from app.services.vapi_service import vapi_service
from app.config import settings
from app.api.deps import get_current_user
from app.models import User

router = APIRouter()

class InterviewConfigRequest(BaseModel):
    name: str = Field(..., min_length=2, max_length=100)
    job_role: str = Field(..., min_length=2, max_length=100)
    experience: str = Field(..., min_length=1)
    difficulty: str = Field(default="Medium", pattern="^(Basic|Medium|Hard)$")

class VapiConfigResponse(BaseModel):
    assistantId: str
    publicKey: str
    overrides: dict

@router.post("/get-vapi-config", response_model=VapiConfigResponse)
async def get_vapi_config(
    request: InterviewConfigRequest,
    # current_user: User = Depends(get_current_user)
):
    """
    Returns Vapi configuration for starting an interview call.
    Protected route - requires authentication.
    """
    try:
        # Create dynamic assistant configuration
        assistant_config = vapi_service.create_interview_assistant_config(
            candidate_name=request.name,
            job_role=request.job_role,
            experience=request.experience,
            difficulty=request.difficulty
        )
        
        # Create assistant (you can cache this for reuse)
        # assistant_id = vapi_service.create_assistant(assistant_config)
        assistant_id = settings.VAPI_ASSISTANT_ID
        
        # Return config for frontend
        return VapiConfigResponse(
            assistantId=assistant_id,
            publicKey=settings.VAPI_PUBLIC_KEY,
            overrides={
                "recordingEnabled": True,
                "variableValues": {
                    "candidateName": request.name,
                    "jobRole": request.job_role
                }
            }
        )
        
    except Exception as e:
        print(f"Vapi Config Error: {e}")
        raise HTTPException(
            status_code=500,
            detail=f"Failed to create interview configuration: {str(e)}"
        )

@router.get("/call-recording/{call_id}")
async def get_call_recording(
    call_id: str,
    # current_user: User = Depends(get_current_user)
):
    """
    Retrieves call recording and transcript after interview ends.
    """
    try:
        recording_data = vapi_service.get_call_recording(call_id)
        
        if not recording_data:
            raise HTTPException(status_code=404, detail="Call recording not found")
        
        return recording_data
        
    except Exception as e:
        print(f"Error fetching recording: {e}")
        raise HTTPException(status_code=500, detail=str(e))