Код: Выделить всё
`INFO: Started server process [8276]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:5050 (Press CTRL+C to quit)
here
Please wait while we connect your call to the A. I. voice assistant, powered by Twilio and the Open-A.I. Realtime APIO.K. you can start talking!
INFO: 34.255.178.120:35938 - "POST /incoming-call HTTP/1.1" 200 OK
WARNING: Invalid HTTP request received.
WARNING: Invalid HTTP request received.
WARNING: Invalid HTTP request received.`
Код: Выделить всё
server {
listen 443 ssl;
server_name 45.133.178.x;
ssl_certificate /etc/letsencrypt/live/45.133.178.x/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/45.133.178.x/privkey.pem;
location /media-stream {
proxy_pass http://localhost:5050;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Код: Выделить всё
@app.api_route("/incoming-call", methods=["GET", "POST"])
async def handle_incoming_call(request: Request):
"""Handle incoming call and return TwiML response to connect to Media Stream."""
response = VoiceResponse()
# punctuation to improve text-to-speech flow
response.say("Please wait while we connect your call to the A. I. voice assistant, powered by Twilio and the Open-A.I. Realtime API")
response.pause(length=1)
response.say("O.K. you can start talking!")
host = request.url.hostname
connect = Connect()
connect.stream(url=f'wss://{host}/media-stream')
response.append(connect)
return HTMLResponse(content=str(response), media_type="application/xml")
@app.websocket("/media-stream")
async def handle_media_stream(websocket: WebSocket):
"""Handle WebSocket connections between Twilio and OpenAI."""
print("Client connected")
await websocket.accept()
Я установил SSL-сертификат, обновил nginx, перезагрузил и перенаправил http на https. я использую wscat для проверки веб-сокета. Я изменил ответ.пауза(длина=60), он просто зависает через 60 секунд.
Подробнее здесь: https://stackoverflow.com/questions/790 ... lio-script