feat: endpoint for caddy

This commit is contained in:
2025-06-09 15:03:58 +05:30
parent 165385358f
commit db20c498c2
6 changed files with 95 additions and 266 deletions
+5 -5
View File
@@ -1,4 +1,4 @@
from fastapi import APIRouter, Depends, Security
from fastapi import APIRouter, Depends
from middleware.auth_dependency import auth_required
from fastapi.security import HTTPBearer
@@ -8,7 +8,7 @@ bearer_scheme = HTTPBearer(scheme_name="Bearer Authentication")
from .endpoints import clinics, doctors, calender, appointments, patients, admin, auth, s3, users, clinicDoctor, dashboard, call_transcripts, notifications,sns, stripe
api_router = APIRouter()
# api_router.include_router(twilio.router, prefix="/twilio")
api_router.include_router(clinics.router, prefix="/clinics", tags=["clinics"], dependencies=[Depends(auth_required)])
api_router.include_router(doctors.router, prefix="/doctors", tags=["doctors"])
@@ -24,9 +24,9 @@ api_router.include_router(sns.router, prefix="/sns", tags=["sns"], include_in_sc
api_router.include_router(stripe.router, prefix="/stripe", tags=["stripe"])
api_router.include_router(
admin.router,
prefix="/admin",
dependencies=[Depends(auth_required)],
admin.router,
prefix="/admin",
dependencies=[Depends(auth_required)],
tags=["admin"])
api_router.include_router(auth.router, prefix="/auth", tags=["auth"])
+8 -2
View File
@@ -1,4 +1,4 @@
from fastapi import APIRouter, BackgroundTasks
from fastapi import APIRouter, BackgroundTasks, Request, status
from services.authService import AuthService
from schemas.CreateSchemas import UserCreate
from schemas.ApiResponse import ApiResponse
@@ -58,4 +58,10 @@ async def verify_otp(data: AuthOTP):
return ApiResponse(
data="OK",
message="OTP verified successfully"
)
)
@router.get("/is-valid-domain")
async def is_valid_domain(req:Request):
host = req.headers.get("host")
is_valid = await ClinicServices().is_valid_domain(host)
return status.HTTP_200_OK if is_valid else status.HTTP_404_NOT_FOUND
+13 -13
View File
@@ -11,19 +11,19 @@ stripe_service = StripeServices()
# async def create_checkout_session(user_id: int):
# return await stripe_service.create_checkout_session(1)
# @router.post("/create-subscription-checkout")
# async def create_subscription_checkout():
# return await stripe_service.create_subscription_checkout(
# fees_to_be={
# "per_call_charges": 10,
# "setup_fees": 100,
# "subscription_fees": 100,
# "total": 210
# },
# clinic_id=1,
# account_id="acct_1RT1UFPTNqn2kWQ8",
# customer_id="cus_SNn49FDltUcSLP"
# )
@router.post("/create-subscription-checkout")
async def create_subscription_checkout():
return await stripe_service.create_subscription_checkout(
fees_to_be={
"per_call_charges": 10,
"setup_fees": 100,
"subscription_fees": 100,
"total": 210
},
clinic_id=1,
account_id="acct_1RT1UFPTNqn2kWQ8",
customer_id="cus_SNn49FDltUcSLP"
)
@router.get("/create-stripe-account-link", dependencies=[Depends(auth_required)])
async def create_stripe_account_link(req:Request):
-183
View File
@@ -1,183 +0,0 @@
# import asyncio
# import json
# import logging
# import os
# from fastapi import APIRouter, Request, WebSocket, status
# from twilio.twiml.voice_response import VoiceResponse, Connect
# from twilio.rest import Client
# from fastapi import WebSocket, Request, Response
# from enum import Enum
# from typing import Optional
# from services.bot import run_bot
# from services.call_state import CallState
# logger = logging.getLogger(__name__)
# router = APIRouter()
# BASE_WS_URL = "wss://13.229.247.61:8000/api/twilio"
# BASE_URL = "http://13.229.247.61:8000/api/twilio"
# DTMF_SWITCH_KEY = "*" # Key to switch between models
# LOG_EVENT_TYPES = [
# "error",
# "response.content.done",
# "rate_limits.updated",
# "response.done",
# "input_audio_buffer.committed",
# "input_audio_buffer.speech_stopped",
# "input_audio_buffer.speech_started",
# "session.created",
# ]
# SHOW_TIMING_MATH = False
# MENU_OPTIONS = """
# Press 1 for Model 1.
# Press 2 for Model 2.
# Press 3 for Model 3.
# Press 4 for Model 4.
# Press 5 for Model 5.
# Press 0 to repeat the options.
# """
# call_state = CallState
# # Define model options as enum for type safety
# class ModelOption(int, Enum):
# MODEL_1 = 1
# MODEL_2 = 2
# MODEL_3 = 3
# MODEL_4 = 4
# MODEL_5 = 5
# @router.post("/call")
# async def get_call():
# SID = os.getenv("TWILIO_SID")
# AUTH_TOKEN = os.getenv("TWILIO_AUTH")
# client = Client(SID, AUTH_TOKEN)
# call = client.calls.create(
# from_="+14149466486",
# to="+917984372159",
# record=True,
# url=f"{BASE_URL}/receive",
# )
# return status.HTTP_200_OK
# # @router.websocket("/media-stream/{id}")
# # async def handle_media_stream(websocket: WebSocket, id: int):
# # """Handle WebSocket connections between Twilio and OpenAI."""
# # print(f"Client connected with id: {id}")
# # await websocket.accept()
# # start_data = websocket.iter_text()
# # await start_data.__anext__()
# # call_data = json.loads(await start_data.__anext__())
# # print(call_data, flush=True)
# # stream_sid = call_data["start"]["streamSid"]
# # print("WebSocket connection accepted")
# # await run_bot(websocket, stream_sid, False, option=id)
# @router.websocket("/media-stream/{id}")
# async def handle_media_stream(websocket: WebSocket, id: int):
# """Handle WebSocket connections between Twilio and OpenAI."""
# logger.info(f"Client connected with id: {id}")
# print(f"Client connected with id: {id}")
# await websocket.accept()
# start_data = websocket.iter_text()
# await start_data.__anext__()
# call_data = json.loads(await start_data.__anext__())
# print(call_data, flush=True)
# logger.info(call_data)
# stream_sid = call_data["start"]["streamSid"]
# print("WebSocket connection accepted")
# logger.info("WebSocket connection accepted")
# await run_bot(websocket, stream_sid, False, option=id)
# # @router.post("/receive")
# # async def receive_call(req: Request):
# # print("----------------- received call -----------------")
# # resp = VoiceResponse()
# # connect = Connect()
# # connect.stream(
# # url=f"wss://allegedly-known-wasp.ngrok-free.app/api/twilio/media-stream"
# # )
# # resp.append(connect)
# # return Response(content=str(resp), media_type="application/xml")
# @router.post("/receive")
# async def receive_call(req: Request):
# print("----------------- received call -----------------")
# resp = VoiceResponse()
# # Gather DTMF input
# gather = resp.gather(
# num_digits=1, action="/api/twilio/handle-key", method="POST", timeout=10
# )
# # Initial greeting and menu options
# gather.say(MENU_OPTIONS)
# # If no input received, redirect back to the main menu
# resp.redirect("/api/twilio/receive")
# return Response(content=str(resp), media_type="application/xml")
# @router.post("/handle-key")
# async def handle_key_press(req: Request):
# """Process the key pressed by the caller and connect to the appropriate model."""
# try:
# form_data = await req.form()
# digits_pressed = form_data.get("Digits", "")
# print(f"User pressed: {digits_pressed}")
# resp = VoiceResponse()
# if digits_pressed == "0":
# # Repeat options
# resp.redirect("/api/twilio/receive")
# elif digits_pressed in "12345":
# # Valid model selection
# model_id = int(digits_pressed)
# resp.say(f"You have selected model {model_id}.")
# # Connect to WebSocket
# connect = Connect()
# connect.stream(url=f"{BASE_WS_URL}/media-stream/{model_id}")
# resp.append(connect)
# else:
# # Invalid selection
# resp.say("Invalid selection. Please try again.")
# resp.redirect("/api/twilio/receive")
# return Response(content=str(resp), media_type="application/xml")
# except Exception as e:
# print(f"Error handling key press: {str(e)}")
# resp = VoiceResponse()
# resp.say(
# "We encountered a problem processing your request. Please try again later."
# )
# return Response(content=str(resp), media_type="application/xml")
# @router.post("/error")
# async def read_item(req: Request):
# print(await req.body())
# print(await req.form())
# logger.error(await req.body())
# return status.HTTP_200_OK