Track NCCO progress

In this code snippet you see how to track how far through an NCCO a caller gets using the notify action

Example

Prerequisites

npm install express

Write the code

Add the following to track-ncco-progress.js:

const Express = require('express');
const app = new Express();

const onInboundCall = (request, response) => {
  const ncco = [
    {
      'action': 'talk',
      'text': 'Thanks for calling the notification line',
    },
    {
      'action': 'notify',
      'payload': {
        'foo': 'bar',
      },
      'eventUrl': [`${request.protocol}://${request.get('host')}/webhooks/notification`],
    },
    {
      'action': 'talk',
      'text': 'You will never hear me as the notification URL will return an NCCO ',
    },
  ];

  response.json(ncco);
};

const onNotification = (_, response) => {
  const ncco = [
    {
      'action': 'talk',
      'text': 'Your notification has been received, loud and clear',
    },
  ];

  response.json(ncco);
};

app
  .get('/webhooks/answer', onInboundCall)
  .post('/webhooks/notification', onNotification);

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 track-ncco-progress.js

Try it out

When you call your Vonage Number you will hear a text-to-speech message and receive a request to your notification URL