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.
- Node.js and a familiarity with how to create a new app.
Set up your Node.js application
First we'll create a Node project using npm.
To create the project, do the following steps:
- Create a folder called
voice-send
- Navigate into the folder you created and run the following command.This command adds 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.
npm init
You can install the Sinch Node.js SDK using either NPM or Yarn:
npm install @sinch/sdk-core
yarn add @sinch/sdk-core
Create your file
Create a new file namedindex.js
in the project and paste the provided "index.js" code into the file.Modify your application
The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values.
Initialize the client
Before initializing a client using this SDK, you'll need your application key and application secret for your Verification app, found on your dashboard.
To start using the SDK, you need to initialize the main client class with your credentials from your Sinch dashboard.
const {SinchClient} = require('@sinch/sdk-core');
const sinchClient = new SinchClient({
applicationKey: "YOUR_application_key",
applicationSecret: "YOUR_application_secret"
});
Note:
For testing purposes on your local environment it's fine to use hardcoded values, but before deploying to production we strongly recommend using environment variables to store the credentials, as in the following example:
.env
File
APPKEY="YOUR_application_key"
APPSECRET="YOUR_application_secret"
app.js
File
const {SinchClient} = require('@sinch/sdk-core');
const sinchClient = new SinchClient({
applicationKey: process.env.APPKEY,
applicationSecret: process.env.APPSECRET
});
Destination number
In this example you want to call a phone number. Change the value of theYOUR_phone_number
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.
Call your phone number
Now you can execute the code and make your text-to-speech call. Run the following command:
node index.js
You should receive a phone call to the number you called with the message "This is a phone call from Sinch."
Next steps
Now that you know how to make a call, learn how to handle an incoming call.