Fortschritte des NCCO verfolgen

In diesem Codeschnipsel sehen Sie, wie Sie verfolgen können, wie weit ein Aufrufer durch ein NCCO kommt unter Verwendung der notify Aktion

Beispiel

Voraussetzungen

npm install express

Schreiben Sie den Code

Fügen Sie Folgendes zu track-ncco-progress.js hinzu:

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}`);
});

Vollständige Quelle anzeigen

Führen Sie Ihren Code aus

Speichern Sie diese Datei auf Ihrem Rechner und führen Sie sie aus:

node track-ncco-progress.js

Probieren Sie es aus

Wenn Sie Ihre Vonage Numbers anrufen, hören Sie eine Text-to-Speech-Nachricht und erhalten eine Anfrage an Ihre Benachrichtigungs-URL