Node.js

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

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

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

'use strict'

const express = require('express');
const WaveFile = require('wavefile').WaveFile;
const fs = require('fs');

const app = express();
const expressWs = require('express-ws')(app);
const port = 3000;

app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.get('/webhooks/answer', (req, res) => {
    let nccoResponse = [
        {
            "action": "talk",
            "text": "Please wait while we connect you to the echo server"
        },
        {
            "action": "connect",
            "from": "NexmoTest",
            "endpoint": [
                {
                    "type": "websocket",
                    "uri": `wss://${req.hostname}/socket`,
                    "content-type": "audio/l16;rate=16000",
                }
            ]
        }
    ]

    res.status(200).json(nccoResponse);
});

app.listen(port, () => console.log(`Listening on port ${port}`));

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