Record a call
A code snippets that shows how to answer an incoming call and set it up to
record, then connect the call. When the call is completed, the eventUrl
you specify in the record action of the NCCO will receive a webhook
including the URL of the recording for download.
Example
Replace the following variables in the example code:
| キー | 説明 |
|---|---|
VONAGE_VIRTUAL_NUMBER | Your Vonage Number. E.g. |
VOICE_TO_NUMBER | The recipient number to call, e.g. |
Prerequisites
npm install express body-parserRun your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.voice with the package containing RecordCall:
Prerequisites
Add the following to build.gradle:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.voice with the package containing RecordCall:
Prerequisites
Install-Package VonagePrerequisites
composer require slim/slim:^3.8 vonage/clientRun your code
Save this file to your machine and run it:
Prerequisites
pip install vonage python-dotenv fastapi[standard]Write the code
Add the following to record-a-call.py:
import os
from os.path import dirname, join
from pprint import pprint
from dotenv import load_dotenv
from fastapi import Body, FastAPI
from vonage_voice import Connect, NccoAction, PhoneEndpoint, Record
dotenv_path = join(dirname(__file__), '../.env')
load_dotenv(dotenv_path)
VONAGE_VIRTUAL_NUMBER = os.environ.get('VONAGE_VIRTUAL_NUMBER')
VOICE_TO_NUMBER = os.environ.get('VOICE_TO_NUMBER')
app = FastAPI()
@app.get('/webhooks/answer')
async def inbound_call():
ncco: list[NccoAction] = [
Record(eventUrl=['https://demo.ngrok.io/webhooks/recordings']),
Connect(
from_=VONAGE_VIRTUAL_NUMBER, endpoint=[PhoneEndpoint(number=VOICE_TO_NUMBER)]
),
]
return [action.model_dump(by_alias=True, exclude_none=True) for action in ncco]
@app.post('/webhooks/recordings')
async def recordings(data: dict = Body(...)):
pprint(data)
return {'message': 'webhook received'}Run your code
Save this file to your machine and run it:
Prerequisites
gem install sinatra sinatra-contribRun your code
Save this file to your machine and run it:
Try it out
You will need to:
- Answer and record the call (this code snippet).
- 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.