Node.js

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

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

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

'use strict'

const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const expressWs = require('express-ws')(app)

app.use(bodyParser.json())

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

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

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