Added call updates

This commit is contained in:
2025-09-24 16:39:05 -04:00
parent f6e22bb975
commit c92183720d
4 changed files with 34 additions and 6 deletions

Binary file not shown.

View File

@@ -4,15 +4,42 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from settings_dev import settings from settings_dev import settings
import requests import requests
from fastapi import FastAPI, HTTPException, status from fastapi import FastAPI, HTTPException, status
from fastapi.middleware.cors import CORSMiddleware
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.responses import JSONResponse
from .voipms_client import update_did_routing, get_forwardings from .voipms_client import update_did_routing, get_forwardings
from .database import Session from .database import Session
from .models import Call from .models import Call
# class AuthMiddleware(BaseHTTPMiddleware):
# async def dispatch(self, request, call_next):
# auth_header = request.headers.get('authorization')
# expected_token = f"Bearer {settings.voipms_api_token}"
# if auth_header != expected_token:
# return JSONResponse(status_code=401, content={"detail": "Unauthorized"})
# response = await call_next(request)
# return response
app = FastAPI( app = FastAPI(
title="EAMCO VoIP.ms Controller", title="EAMCO VoIP.ms Controller",
description="An API to manage routing for a VoIP.ms DID.", description="An API to manage routing for a VoIP.ms DID.",
version="1.0.0", version="1.0.0",
) )
app.add_middleware(
CORSMiddleware,
allow_origins=settings.origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/", tags=["General"])
def read_root():
"""A simple root endpoint to confirm the API is running."""
return {"message": f"Welcome to the VoIP.ms API for DID: {settings.target_did}"}
# app.add_middleware(AuthMiddleware)
@app.get("/test/forwardings") @app.get("/test/forwardings")
def test_get_forwardings(): def test_get_forwardings():
try: try:
@@ -23,6 +50,8 @@ def test_get_forwardings():
} }
except HTTPException as e: except HTTPException as e:
raise e raise e
@app.get("/test/did") @app.get("/test/did")
def test_did_info(): def test_did_info():
params = { params = {
@@ -40,11 +69,7 @@ def test_did_info():
return {"error": f"Failed to connect to VoIP.ms API: {str(e)}", "params": params} return {"error": f"Failed to connect to VoIP.ms API: {str(e)}", "params": params}
except Exception as e: except Exception as e:
return {"error": f"Unexpected error: {str(e)}", "params": params} return {"error": f"Unexpected error: {str(e)}", "params": params}
@app.get("/", tags=["General"])
def read_root():
"""A simple root endpoint to confirm the API is running."""
return {"message": f"Welcome to the VoIP.ms API for DID: {settings.target_did}"}
@app.post("/route/sip", status_code=status.HTTP_200_OK, tags=["DID Routing"]) @app.post("/route/sip", status_code=status.HTTP_200_OK, tags=["DID Routing"])
def route_to_sip_account(): def route_to_sip_account():
@@ -123,4 +148,4 @@ def route_to_cellphone_2():
"voipms_response": result "voipms_response": result
} }
except HTTPException as e: except HTTPException as e:
raise e raise e

View File

@@ -53,6 +53,9 @@ class ApplicationConfig:
# VoIP.ms API endpoint # VoIP.ms API endpoint
voipms_api_url = os.environ.get('VOIPMS_API_URL', "https://voip.ms/api/v1/rest.php") voipms_api_url = os.environ.get('VOIPMS_API_URL', "https://voip.ms/api/v1/rest.php")
# API Token for Frontend Authentication
voipms_api_token = os.environ.get('VOIPMS_API_TOKEN')
# Create a single instance of the settings to be used throughout the app # Create a single instance of the settings to be used throughout the app
settings = ApplicationConfig() settings = ApplicationConfig()