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"}