Receive an inbound call

This code snippet demonstrates how to receive an inbound call on your Smart Number.

Prerequisites

Create an Application

Check out Getting Started with Vonage CLI for more information on how to install and configure the CLI.

Use the following command to create a Vonage application:

vonage apps create 'Your application'✅ Creating ApplicationSaving private key ... Done!Application createdName: Your applicationApplication ID: 00000000-0000-0000-0000-000000000000Improve AI: OffPrivate/Public Key: SetCapabilities: None Enabled

Once you have the application, you then need to add the voice capabilities; make sure you replace the webhook URLs with your own:

vonage apps capabilities update 00000000-0000-0000-0000-000000000000 voice \ --voice-answer-url='https://example.com/webhooks/voice/answer' \ --voice-event-url='https://example.com/webhooks/voice/event' \ --voice-fallback-url='https://example.com/webhooks/voice/fallback'✅ Fetching Application✅ Adding voice capability to application 00000000-0000-0000-0000-000000000000Name: Your applicationApplication ID: 00000000-0000-0000-0000-000000000000Improve AI: OffPrivate/Public Key: SetCapabilities: VOICE: Uses Signed callbacks: On Conversation TTL: 41 hours Leg Persistence Time: 6 days Event URL: [POST] https://example.com/webhooks/voice/event Answer URL: [POST] https://example.com/webhooks/voice/answer Fallback URL: [POST] https://example.com/webhooks/voice/fallback

The application is then created and has the required capabilities. Creating an application and adding application capabilities are covered in detail in the application overview.

Install dependencies

npm install express

Initialize your dependencies

Create a file named receive-an-inbound-call.js and add the following code:

Write the code

Add the following to receive-an-inbound-call.js:

Try it out

Save the file to your machine and run it using the following command:

node receive-an-inbound-call.js

When you call your Smart Number you will hear a text-to-speech message.