Record a named conversation

A code snippet that shows how to record a conversation. Answer an incoming call and return an NCCO that joins the caller to a named conversation. By setting record to true, the conversation is recorded and when the call is complete, a webhook is sent to the eventUrl you specify. The webhook includes the URL of the recording.

Example

Prerequisites

npm install express body-parser

Write the code

Add the following to record-a-conversation.js:

const Express = require('express');
const bodyParser = require('body-parser');

const app = new Express();
app.use(bodyParser.json());

const onInboundCall = (request, response) => {
  const ncco = [
    {
      'action': 'conversation',
      'name': VOICE_CONF_NAME,
      'record': 'true',
      'eventMethod': 'POST',
      'eventUrl': [`${request.protocol}://${request.get('host')}/webhooks/recordings`],
    },
  ];

  response.json(ncco);
};

const onRecording = (request, response) => {
  const recording_url = request.body?.recording_url;
  console.log(`Recording URL = ${recording_url}`);

  response.status(204).send();
};

app
  .get('/webhooks/answer', onInboundCall)
  .post('/webhooks/recordings', onRecording);

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

View full source

Run your code

Save this file to your machine and run it:

node record-a-conversation.js

Try it out

You will need to:

  1. Record a conversation by dialling your Vonage Number (this code snippet).
  2. Download the recording. See the Download a recording code snippet for how to do this.

Further Reading

  • Call Recording - Recording audio input from a caller or recording the conversation between two callers.