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:
Note:
Before you can get started, you need the following already set up:
- Set all Voice API configuration settings.
- NPM and a familiarity with how to install packages.
- Node.js and a familiarity with how to create a new app.
Set up your Node.js application
To quickly get started setting up a simple client application using the Node SDK:
- If you haven't already, clone the sinch-sdk-node-quickstart repository.
- Navigate to the
templates/client
folder. - Open a command prompt or terminal and run the following command to install the necessary dependencies:
npm install
- Open the
.env
file. Using the Voice app credentials from your Sinch Customer Dashboard, populate the following fields with your values:
Field | Description |
---|---|
SINCH_APPLICATION_KEY | The unique ID of your application. |
SINCH_APPLICATION_SECRET | The secret for your application. |
- Save the file.
Modify your application
- Navigate to the
/templates/client/src/voice/
folder and open thesnippet.js
file. Replace the existing content within that file with thesnippet.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 therecipientPhoneNumber
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 thecallingNumber
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:
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.