Route to a VBC Extension
This code snippet demonstrates how to connect an inbound call on a Smart Number to an extension.
Example
The following example shows how to receive the inbound call and immediately forward it to your chosen VBC extension.
You achieve this with a connect action in the Vonage API Platform Call Control Object (NCCO). Create an endpoint with a type of vbc and the extension you want to forward the call to.
Prerequisites
Create an Application
Go to the Application's page on the Dashboard, and define a Name for your Application.

Make sure to click on the Generate public and private key button, and keep the file private.key around.
Then, enable the Voice capability. For the moment, leave everything by default.

Finally, click Generate new application at the bottom of the page.
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 Application
Saving private key ... Done!
Application created
Name: Your application
Application ID: 00000000-0000-0000-0000-000000000000
Improve AI: Off
Private/Public Key: Set
Capabilities:
None Enabled
vonage apps create 'Your application'
✅ Creating Application
Saving private key ... Done!
Application created
Name: Your application
Application ID: 00000000-0000-0000-0000-000000000000
Improve AI: Off
Private/Public Key: Set
Capabilities:
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-000000000000
Name: Your application
Application ID: 00000000-0000-0000-0000-000000000000
Improve AI: Off
Private/Public Key: Set
Capabilities:
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
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-000000000000
Name: Your application
Application ID: 00000000-0000-0000-0000-000000000000
Improve AI: Off
Private/Public Key: Set
Capabilities:
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 documentation.
Install dependencies
Initialize your dependencies
Create a file named connect-to-extension.js and add the following code:
const app = require('express')()
Write the code
Add the following to connect-to-extension.js:
const onInboundCall = (request, response) => {
const ncco = [{
action: 'connect',
endpoint: [{
type: 'vbc',
extension: VBC_EXTENSION
}]
}]
response.json(ncco)
}
app.get('/webhooks/answer', onInboundCall)
app.listen(3000)
Try it out
Save the file to your machine and run it using the following command:
When you call your Smart Number it should immediately forward the call to the extension number you specified.