メッセージを録音する

会話を録音する方法を示すコード・スニペット。着信に応答し を含むNCCOを返す。 record アクションを実行する。呼び出しが完了すると に送られる。 eventUrl を指定します。ウェブフックには 録画のURL

Prerequisites

npm install express body-parser

Write the code

Add the following to record-a-message.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: 'talk',
      text: 'Please leave a message after the tone, then press #. We will get back to you as soon as we can.',
    },
    {
      action: 'record',
      endOnKey: '#',
      beepStart: 'true',
      endOnSilence: '3',
      eventUrl: [`${request.protocol}://${request.get('host')}/webhooks/recordings`],
    },
    {
      action: 'talk',
      text: 'Thank you for your message. Goodbye.',
    },
  ];

  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-message.js

試してみる

必要なのは

  1. Vonage番号にダイヤルしてメッセージを録音し、発信音の後にメッセージを残してください(このコードスニペット)。
  2. 録画をダウンロードするを見る 録音をダウンロードする のコード・スニペットで説明している。

さらに読む

  • ボイスメール - .NETとVonage Voice APIを使って着信コールの音声を録音する方法をご紹介します。