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}`));
について type の endpoint は websocketその uri は /socket WebSocketサーバーがアクセスできるルートと content-type は音質を指定します。
オーディオをWebSocketで再生する
Voice APIコールをWebSocketに接続し、JavaScriptで音声を再生する方法をご紹介します。
以下の言語で利用可能:
手順
1
このタスクの紹介2
Prerequisites3
Vonage番号の購入4
音声アプリケーションの作成5
Vonage番号をリンクする6
プロジェクトの作成7
回答のウェブフックを書く8
イベントウェブフックを書く9
WebSocketの作成10
アプリケーションのテスト11
次はどうする?