Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Response
|
| 2 |
+
import requests
|
| 3 |
+
from typing import Dict, Any
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
# Constants
|
| 8 |
+
API_URL = "https://api.vapi.ai/call/phone"
|
| 9 |
+
ASSISTANT_ID = "2eecd792-ab43-41d6-b991-12b3cac916ab"
|
| 10 |
+
PHONE_NUMBER_ID = "d8bedb89-8bbb-4ad3-8283-39b2ea2d2a69"
|
| 11 |
+
AUTH_TOKEN = "e1ca5a8d-047e-4802-b54a-237ad07f68c9"
|
| 12 |
+
|
| 13 |
+
@app.post("/emergency-call")
|
| 14 |
+
async def make_emergency_call(request: Dict[Any, Any]):
|
| 15 |
+
# Using the specified phone number
|
| 16 |
+
customer_number = "919035576651"
|
| 17 |
+
|
| 18 |
+
if not customer_number.startswith("+"):
|
| 19 |
+
customer_number = "+" + customer_number
|
| 20 |
+
|
| 21 |
+
headers = {
|
| 22 |
+
"Authorization": f"Bearer {AUTH_TOKEN}",
|
| 23 |
+
"Content-Type": "application/json",
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
payload = {
|
| 27 |
+
"assistantId": ASSISTANT_ID,
|
| 28 |
+
"phoneNumberId": PHONE_NUMBER_ID,
|
| 29 |
+
"customer": {
|
| 30 |
+
"number": customer_number
|
| 31 |
+
},
|
| 32 |
+
"assistant": {
|
| 33 |
+
"firstMessage": "Hello, This is an emergency call from priya.",
|
| 34 |
+
"model": {
|
| 35 |
+
"provider": "openai",
|
| 36 |
+
"model": "gpt-3.5-turbo",
|
| 37 |
+
"messages": [
|
| 38 |
+
{
|
| 39 |
+
"role": "system",
|
| 40 |
+
"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"
|
| 41 |
+
}
|
| 42 |
+
]
|
| 43 |
+
},
|
| 44 |
+
"voice": "jennifer-playht"
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
try:
|
| 49 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 50 |
+
if response.status_code == 201:
|
| 51 |
+
return {"status": "success", "data": response.json()}
|
| 52 |
+
else:
|
| 53 |
+
return {"status": "error", "message": response.text}
|
| 54 |
+
except Exception as e:
|
| 55 |
+
return {"status": "error", "message": str(e)}
|
| 56 |
+
|
| 57 |
+
@app.get("/")
|
| 58 |
+
async def read_root():
|
| 59 |
+
return {"message": "Emergency Call System API"}
|