Python
Write your answer webhook
When Vonage receives an inbound call on your virtual number, it will make a request to your /webhooks/answer route. This route should accept an HTTP GET request and return a Nexmo Call Control Object (NCCO) that tells Vonage how to handle the call.
Your NCCO should use the text action to greet the caller, and the connect action to connect the call to your webhook endpoint:
#!/usr/bin/env python3
from flask import Flask, request, jsonify
from flask_sock import Sock
app = Flask(__name__)
sock = Sock(app)
@app.route("/webhooks/answer")
def answer_call():
ncco = [
{
"action": "talk",
"text": "We will now connect you to the echo server, wait a moment then start speaking.",
},
{
"action": "connect",
"from": "Vonage",
"endpoint": [
{
"type": "websocket",
"uri": f"wss://{request.host}/socket",
"content-type": "audio/l16;rate=16000",
}
],
},
]
return jsonify(ncco)
The type of endpoint is websocket, the uri is the /socket route where your WebSocket server will be accessible and the content-type specifies the audio quality.
Connect to a WebSocket
Connect an inbound call to a WebSocket with the Voice API
手順
1
Introduction2
Prerequisites3
Buy a Vonage number4
Create a Voice Application5
Link a Vonage number6
Create the project7
Write your answer webhook8
Write your event webhook9
Create the WebSocket10
Test your application11
Conclusion12
What's next?