Make a call with Node.js

You can quickly see how the Voice API works by calling yourself using the API.

In this guide you will learn how to:

Learn how to:
  1. Set up your Node.js application
  2. Call your phone number

What you need to know before you start

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

Set up your Node.js application

First we'll create a Node project using npm. This creates a package.json and the core dependencies necessary to start coding.

To create the project, do the following steps:

  1. Create a folder called voice-send
  2. Navigate into the folder you created and run the following command.
    Copy
    Copied
    npm init

    This command adds the node_modules folder and the package.json file. You will be prompted to provide values for the fields. For this tutorial, you can simply accept the default values and press enter at each stage.

  3. Add the fetch package with npm to generate the necessary dependencies.
Copy
Copied
npm install 'cross-fetch'

Create your file

Create a new file named index.js in the project and paste the provided "Make a phone call" code into the file.

Note:

This tutorial uses basic authentication for testing purposes. We recommend using a signed request for authentication in a production environment. You can follow the steps in this guide, but use the code samples from here to use request signing authentication instead.

Fill in your parameters

Assign your values to the following parameters:

ParameterYour value
APPLICATION_KEYThe key found on your Sinch dashboard.
APPLICATION_SECRETThe secret found on your Sinch dashboard.
SINCH_NUMBERAny number you've assigned to your application. This can be a number you've purchased or your free test number. Find the number on your Sinch dashboard by clicking on your app, navigating to the Voice and Video tab, and looking in the Inbound Numbers section.
LOCALEThe language and locale you want to use for the text-to-speech call. Locale is specified with a language code according to ISO 639, a dash and a country code according to ISO 3166-1 alpha-2. For example, American English is represented by en-US.
TO_NUMBERThe phone number that you want to call.

Save the file.

Call your phone number

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

Copy
Copied
node index.js

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

Tip:
If the text-to-speech message starts playing too early for your needs, you can use SSML to add a pause at the beginning of the message.
Troubleshooting tip

If after running your app you receive a 5000 error response, you may have forgotten to save your file after adding your authentication values. This is an easy mistake to make! Try saving the file and running the app again.

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.