Make a call with Node.js SDK

You can quickly see how the Voice API works by calling yourself using the API and the Node.js SDK.

In this guide you will learn how to:

  1. Set up your Node.js application
  2. Call your phone number
Note:

Before you can get started, you need the following already set up:

Set up your Node.js application

To quickly get started setting up a simple client application using the Node SDK:

  1. If you haven't already, clone the sinch-sdk-node-quickstart repository.
  2. Navigate to the templates/client folder.
  3. Open a command prompt or terminal and run the following command to install the necessary dependencies:
    Copy
    Copied
    npm install
  4. Open the .env file. Using the Voice app credentials from your Sinch Customer Dashboard, populate the following fields with your values:
FieldDescription
SINCH_APPLICATION_KEYThe unique ID of your application.
SINCH_APPLICATION_SECRETThe secret for your application.
  1. Save the file.

Modify your application

  1. Navigate to the /templates/client/src/voice/ folder and open the snippet.js file. Replace the existing content within that file with the snippet.js code provided on this page. That code is also found here if you want to just replace the file.

The code provided in snippet.js includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values.

Destination number

In this example you want to call a phone number. Change the value of the recipientPhoneNumber parameter to the phone number you verified in your dashboard in E.164 format.
Note:

When your account is in trial mode, you can only call your verified numbers. If you want to call any number, you need to upgrade your account!

Save the file.

Calling number

Using the Voice API you can set what number you want to appear in the caller ID of the person you're calling. This is called setting the CLI. In the callingNumber parameter, set the number you want to appear. In this instance, use the Sinch number you have assigned to your Voice app.

Call your phone number

Now you can execute the code and make your text-to-speech call. Run the following command:

Copy
Copied
node src/app.js

You should receive a phone call to the number you called with the message "Hello, this is a call from Sinch."

Next steps

Now that you know how to make a call, learn how to handle an incoming call.

Additional resources

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.