Skip to content

Latest commit

 

History

History

outbound-call-ivr

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Telnyx-Node Outbound TeXML Call Demo

Telnyx

Sample application demonstrating Telnyx-Node IVR with TeXML

Documentation & Tutorial

The full documentation and tutorial is available on developers.telnyx.com

Pre-Reqs

You will need to set up:

What you can do

  • Create an outbound call to your phone number
  • Respond to a math question after answering the call
  • Call your Telnyx number for the same math question

Usage

The following environmental variables need to be set

Variable Description
TELNYX_API_KEY Your Telnyx API Key
TELNYX_PUBLIC_KEY Your Telnyx Public Key
TELNYX_APP_PORT Defaults to 8000 The port the app will be served
BASE_URL Your NGROK DOMAIN like "http://your-url.ngrok.io"
TELNYX_CONNECTION_ID The ID of the TeXML call-control-connection to use for placing the calls

.env file

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_PUBLIC_KEY="KEYasdf"
TELNYX_API_KEY="+kWXUag92mcU="
TELNYX_APP_PORT=8000
TELNYX_CONNECTION_ID=1494404757140276705
BASE_URL="http://your-url.ngrok.io"

Callback URLs For Telnyx Applications

Callback Type URL
Outbound Call-Control Status Callback {ngrok-url}/call-control/answer
Inbound Call-Control Status Callback {ngrok-url}/call-control/answer

Install

Run the following commands to get started

$ git clone https://github.com/team-telnyx/demo-node-telnyx.git

Notes!

TeXML sends webhooks with Content-Type: application/x-www-form-urlencoded. As such; our express application should be configured to accept form encoded payloads.

Adding app.use(express.urlencoded({ extended: true })); to the application allows us to reference req.body to get the Webhook data.

Ngrok

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 application to generated ngrok URL + path (Example: http://{your-url}.ngrok.io/call-control/answer).

Run

Start the server node index.js

When you are able to run the server locally, the final step involves making your application accessible from the internet. So far, we've set up a local web server. This is typically not accessible from the public internet, making testing inbound requests to web applications difficult.

The best workaround is a tunneling service. They come with client software that runs on your computer and opens an outgoing permanent connection to a publicly available server in a data center. Then, they assign a public URL (typically on a random or custom subdomain) on that server to your account. The public server acts as a proxy that accepts incoming connections to your URL, forwards (tunnels) them through the already established connection and sends them to the local web server as if they originated from the same machine. The most popular tunneling tool is ngrok. Check out the ngrok setup walkthrough to set it up on your computer and start receiving webhooks from inbound messages to your newly created application.

Once you've set up ngrok or another tunneling service you can add the public proxy URL to your Inbound Settings in the Mission Control Portal. To do this, click the edit symbol [✎] next to your TeXML Applications. In the "Inbound Settings" > "Webhook URL" field, paste the forwarding address from ngrok into the Webhook URL field. Add call-control/answer to the end of the URL to direct the request to the webhook endpoint in your server.

For now you'll leave “Failover URL” blank, but if you'd like to have Telnyx resend the webhook in the case where sending to the Webhook URL fails, you can specify an alternate address in this field.

Create the call

The service exposes a path at http://your-url.ngrok.io/calls to accept a JSON post request with the to & from number to create the outbound call. Where the to number is your Cell Number and the from is your Telnyx number.

curl --location --request POST 'http://your-url.ngrok.io/calls' \
--header 'Content-Type: application/json' \
--data-raw '{
    "to": "+19198675309",
    "from": "+19842550944"
}'