Node.js
Create the WebSocket
First, handle the connection event so that you can report when your webhook server is online and ready to receive the call audio:
expressWs.getWss().on('connection', function (ws) {
console.log('Websocket connection is open');
});
Then, create a route handler for the /socket route. This listens for a message event which is raised every time the WebSocket receives audio from the call. Your application should respond by echoing the audio back to the caller with the send() method:
app.ws('/socket', (ws, req) => {
ws.on('message', (msg) => {
ws.send(msg)
})
})
Connect to a WebSocket
Connect an inbound call to a WebSocket with the Voice API
Steps
1
Introduction2
Prerequisites3
Buy a Vonage number4
Create a Voice Application5
Link a Vonage number6
Create the project7
Write your answer webhook8
Write your event webhook9
Create the WebSocket10
Create your server11
Test your application12
Conclusion13
What's next?