Python

回答のウェブフックを書く

Vonageはバーチャル番号で着信コールを受けると、以下のリクエストを行います。 /webhooks/answer ルートに接続します。このルートはHTTPの GET リクエストを返し ネクスモ・コール・コントロール・オブジェクト(NCCO) これは、Vonageにコールの処理方法を指示するものです。

NCCOは text というアクションを実行します。 connect アクションを使用して、呼び出しを Webhook エンドポイントに接続します:

#!/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)

について typeendpointwebsocketその uri/socket WebSocketサーバーがアクセスできるルートと content-type は音質を指定します。