File size: 1,897 Bytes
6962fd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26c6e53
6962fd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, Response
import requests
from typing import Dict, Any

app = FastAPI()

# Constants
API_URL = "https://api.vapi.ai/call/phone"
ASSISTANT_ID = "2eecd792-ab43-41d6-b991-12b3cac916ab"
PHONE_NUMBER_ID = "d8bedb89-8bbb-4ad3-8283-39b2ea2d2a69"
AUTH_TOKEN = "e1ca5a8d-047e-4802-b54a-237ad07f68c9"

@app.post("/emergency-call")
async def make_emergency_call(request: Dict[Any, Any]):
    # Using the specified phone number
    customer_number = "919480723193"
    
    if not customer_number.startswith("+"):
        customer_number = "+" + customer_number

    headers = {
        "Authorization": f"Bearer {AUTH_TOKEN}",
        "Content-Type": "application/json",
    }

    payload = {
        "assistantId": ASSISTANT_ID,
        "phoneNumberId": PHONE_NUMBER_ID,
        "customer": {
            "number": customer_number
        },
        "assistant": {
            "firstMessage": "Hello, This is an emergency call from priya.",
            "model": {
                "provider": "openai",
                "model": "gpt-3.5-turbo",
                "messages": [
                    {
                        "role": "system",
                        "content": "You are an AI assistant who job is to speak that priya is in emergency, is being chased by few people, and this her address BKG sapphire, KITS, bangalore"
                    }
                ]
            },
            "voice": "jennifer-playht"
        }
    }

    try:
        response = requests.post(API_URL, headers=headers, json=payload)
        if response.status_code == 201:
            return {"status": "success", "data": response.json()}
        else:
            return {"status": "error", "message": response.text}
    except Exception as e:
        return {"status": "error", "message": str(e)}

@app.get("/")
async def read_root():
    return {"message": "Emergency Call System API"}