Sample application demonstrating Telnyx-Node Call Control functionality.
You will need to set up:
- Telnyx Account
- Telnyx Phone Number enabled with:
- Node & NPM installed
This app, when running has the following behavior for inbound and outbound calls:
Inbound:
- Receives inbound callback
- Answers the call
- Speaks a sentence and waits for speak.ended callback
- Ends the call
Outbound:
- Makes the call to the specified number
- On answer, speaks audio
- Waits for speak.ended callback
- Ends the call
The following environmental variables need to be set
Variable | Description |
---|---|
TELNYX_API_KEY |
Your Telnyx API Key |
TELNYX_NUMBER |
Your Telnyx Phone Number |
TELNYX_CONNECTION_ID |
Your Telnyx Call Control Application ID |
TELNYX_APP_PORT |
Defaults to 8000 The port the app will be served. |
This app uses the excellent dotenv package to manage environment variables.
Make a copy of .env.sample
and save as .env
and update the variables to match your creds.
TELNYX_API_KEY=""
TELNYX_NUMBER=""
TELNYX_CONNECTION_ID=""
TELNYX_APP_PORT=8000
This application is served on the port defined in the runtime environment (or in the .env
file). Be sure to launch ngrok for that port
./ngrok http 8000
Terminal should look something like
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Account Little Bobby Tables (Plan: Free)
Version 2.3.35
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://your-url.ngrok.io -> http://localhost:8000
Forwarding https://your-url.ngrok.io -> http://localhost:8000
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
At this point you can point your Call Control Application webhook url to generated ngrok URL + path. For this example, the url will be http://{your-url}.ngrok.io/call_control
Run the following commands to get started
$ git clone https://github.com/d-telnyx/demo-node-telnyx.git
$ cd express-call-control
Start the server npm run start
When the application is started, express serves it to the port specified in the .env file (Default 8000), so you can sipmly take a look at the application at localhost:8000.
Note: You must enter phone number in E.164 format (i.e. +12345678910) for the call to be sent correctly.
Once everything is setup, you should now be able to:
- Make calls to a specified outbound number
- Receive an inbound call