Suivre les progrès du NCCO

Dans cet extrait de code, vous voyez comment suivre l'état d'avancement d'un NCCO pour un appelant en utilisant le notify action

Exemple

Conditions préalables

npm install express

Rédiger le code

Ajouter ce qui suit à 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}`);
});

Voir la source complète

Exécutez votre code

Enregistrez ce fichier sur votre machine et exécutez-le :

node track-ncco-progress.js

Essayez-le

Lorsque vous appelez votre Numbers Vonage, vous entendrez un message de synthèse vocale et recevrez une demande d'accès à votre URL de notification