Earmuff a call

This code snippet earmuffs and unearmuffs a call. When a call is earmuffed, the user cannot hear other participants, but other participants can hear the user.

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 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

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.

Rent a Number

You can rent a number using the Vonage CLI. The following command searches for an available number in the United States:

vonage numbers search US ✅ Searching for numbers There is 1 number available for purchase in United States Number Type Features Monthly Cost Setup Cost ----------- ------ --------------- ------------ ---------- 16127779311 Mobile MMS, SMS, VOICE €0.90 €0.00 Use vonage numbers buy to purchase.

Use this command to purchase a number:

vonage numbers buy US 16127779311 ✅ Searching for numbers Are you sure you want to purchase the number 16127779311 for €0.90? [y/n] y ✅ Purchasing number Number 16127779311 purchased Number: 16127779311 Country: 🇺🇸 United States Type: Mobile Features: MMS, SMS, VOICE Monthly Cost: €0.90 Setup Cost: €0.00 Linked Application ID: Not linked to any application Voice Callback: Not Set Voice Callback Value: Not Set Voice Status Callback: Not Set

Specify an alternative two-character country code to purchase a number in another country.

Now that you have both an application and a number, you need to link them together.

vonage apps numbers link 00000000-0000-0000-0000-000000000000 16127779311 ✅ Fetching Application Fetching Owned numbers [===============================================] 1/1 100% Number linked Number: 16127779311 Country: 🇺🇸 United States Type: Toll-free Features: MMS, SMS, VOICE Monthly Cost: Not Set Setup Cost: Not Set Linked Application ID: 00000000-0000-0000-0000-000000000000 Voice Callback: app Voice Callback Value: 00000000-0000-0000-0000-000000000000 Voice Status Callback: Not Set

Example

Replace the following variables in the example code:

KeyDescription
VOICE_CALL_ID

The UUID of the call leg.

Prerequisites

Execute the following command at your terminal prompt to create the JWT for authentication:

Write the code

Add the following to earmuff-a-call.sh:

View full source

Run your code

Save this file to your machine and run it:

bash earmuff-a-call.sh

Try it out

When you run the code the call identified by UUID will be earmuffed or unearmuffed.

Further Reading

  • Conference Calling - This guide explains the two concepts Vonage associates with a call, a leg and a conversation.