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)
})
について type の endpoint は websocketその uri は /socket WebSocketサーバーがアクセスできるルートと content-type は音質を指定します。
WebSocketに接続する
Voice APIでインバウンドコールをWebSocketに接続する
手順
1
はじめに2
Prerequisites3
Vonage番号の購入4
音声アプリケーションの作成5
Vonage番号をリンクする6
プロジェクトの作成7
回答のウェブフックを書く8
イベントウェブフックを書く9
WebSocketの作成10
サーバーの作成11
アプリケーションのテスト12
結論13
次はどうする?