John George
04/30/2025, 4:38 AMpy
from fastapi import FastAPI, Request, HTTPException
import uvicorn
app = FastAPI()
@app.post("/assistant-request")
async def assistant_request(request: Request):
# Parse incoming JSON
payload = await request.json()
message = payload.get("message", {})
# Extract the caller's number
caller_number = message.get("customer", {}).get("number")
if not caller_number:
raise HTTPException(status_code=400, detail="Missing caller number")
# Hardcoded assistant ID
assistant_id = "hardcoded-assistant-id"
# Build response payload
response = {
"assistantId": assistant_id,
"assistantOverrides": {
"variableValues": {
"callerNumber": caller_number
}
}
}
return response
if __name__ == "__main__":
# Run with: python fastapi_assistant_server.py
uvicorn.run(app, host="0.0.0.0", port=8000)
you could run that with ngrok, set your serverUrl to https://your-ngrok-url/assistant-request, add your assistant's ID with the {{callerNumber}} in there, and it should work 🙂