This quickstart shows you how to build your first server-side application that makes and receives phone calls. For other voice quickstarts, such as no-code or SDK quickstarts, see Programmable Voice quickstarts.
Copy your Account SID and set it as an environment variable using the following command. Replace YOUR_ACCOUNT_SID with your actual Account SID.
exportTWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID
Create an API key, then set the key SID and secret as environment variables using the following commands. Replace YOUR_API_KEY and YOUR_API_SECRET with your actual values.
Copy your Account SID and set it as an environment variable using the following command. Replace YOUR_ACCOUNT_SID with your actual Account SID.
setTWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID
Create an API key, then set the key SID and secret as environment variables using the following commands. Replace YOUR_API_KEY and YOUR_API_SECRET with your actual values.
Copy your Account SID and set it as an environment variable using the following command. Replace YOUR_ACCOUNT_SID with your actual Account SID.
$Env:TWILIO_ACCOUNT_SID="YOUR_ACCOUNT_SID"
Create an API key, then set the key SID and secret as environment variables using the following commands. Replace YOUR_API_KEY and YOUR_API_SECRET with your actual values.
1
$Env:TWILIO_API_KEY="YOUR_API_KEY"
2
$Env:TWILIO_API_SECRET="YOUR_API_SECRET"
Make an outgoing phone call
To make a phone call from your Twilio number, follow these steps:
PythonNode.jsPHPC# or .NETJavaGoRuby
Create a file named make_call.py and add the following code:
Make a phone call using Twilio
1
# Download the helper library from https://www.twilio.com/docs/python/install
2
importos
3
fromtwilio.restimportClient
4
5
# Find your Account SID at twilio.com/console
6
# Provision API Keys at twilio.com/console/runtime/api-keys
7
# and set the environment variables. See http://twil.io/secure
8
# For local testing, you can use your Account SID and Auth token
9
api_key=os.environ["TWILIO_API_KEY"]
10
api_secret=os.environ["TWILIO_API_SECRET"]
11
account_sid=os.environ["TWILIO_ACCOUNT_SID"]
12
client=Client(api_key, api_secret, account_sid)
13
14
call=client.calls.create(
15
url="http://demo.twilio.com/docs/voice.xml",
16
to="+18005550100",
17
from_="+18005550199",
18
)
19
20
print(call.sid)
Replace the from_ phone number with your Twilio number.
Replace the to phone number with your own phone number.
Save your changes.
Run the script:
pythonmake_call.py
Your phone rings and you hear the short message in the [TwiML][] document that links to your script.
Create a file named make_call.js in the folder where you installed Express and the Twilio SDK.
Add the following code to make_call.js:
Make an outbound call
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
consttwilio=require("twilio");// Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID at twilio.com/console
5
// Provision API Keys at twilio.com/console/runtime/api-keys
6
// and set the environment variables. See http://twil.io/secure
7
// For local testing, you can use your Account SID and Auth token
If Twilio needs your compliance data, create a compliance profile first.
Click the Configuration details tab.
Click Messaging > Edit details.
On the Edit messaging configuration dialog, select the Webhook, TwiML Bin, Function, Studio Flow, Proxy Service option.
Under How do you want to set up your primary method?, select Webhook.
Paste your ngrok public URL in the URL box.
If your ngrok console shows Forwarding https://<your-app-name>.ngrok.dev, paste https://<your-app-name>.ngrok.dev to the URL box.
If you use the legacy Console, follow these steps:
If Twilio needs your compliance data, create a compliance profile first.
Click the Configuration details tab.
Click Messaging > Edit details.
On the Edit messaging configuration dialog, select the Webhook, TwiML Bin, Function, Studio Flow, Proxy Service option.
Under How do you want to set up your primary method?, select Webhook.
Paste your ngrok public URL in the URL box.
If your ngrok console shows Forwarding https://<your-app-name>.ngrok.dev, paste https://<your-app-name>.ngrok.dev to the URL box.
If you use the legacy Console, follow these steps:
If Twilio needs your compliance data, create a compliance profile first.
Click the Configuration details tab.
Click Messaging > Edit details.
On the Edit messaging configuration dialog, select the Webhook, TwiML Bin, Function, Studio Flow, Proxy Service option.
Under How do you want to set up your primary method?, select Webhook.
Paste your ngrok public URL in the URL box.
If your ngrok console shows Forwarding https://<your-app-name>.ngrok.dev, paste https://<your-app-name>.ngrok.dev to the URL box.
If you use the legacy Console, follow these steps:
If Twilio needs your compliance data, create a compliance profile first.
Click the Configuration details tab.
Click Messaging > Edit details.
On the Edit messaging configuration dialog, select the Webhook, TwiML Bin, Function, Studio Flow, Proxy Service option.
Under How do you want to set up your primary method?, select Webhook.
Paste your ngrok public URL in the URL box.
If your ngrok console shows Forwarding https://<your-app-name>.ngrok.dev, paste https://<your-app-name>.ngrok.dev to the URL box.
If you use the legacy Console, follow these steps:
If Twilio needs your compliance data, create a compliance profile first.
Click the Configuration details tab.
Click Messaging > Edit details.
On the Edit messaging configuration dialog, select the Webhook, TwiML Bin, Function, Studio Flow, Proxy Service option.
Under How do you want to set up your primary method?, select Webhook.
Paste your ngrok public URL in the URL box.
If your ngrok console shows Forwarding https://<your-app-name>.ngrok.dev, paste https://<your-app-name>.ngrok.dev to the URL box.
If you use the legacy Console, follow these steps:
If Twilio needs your compliance data, create a compliance profile first.
Click the Configuration details tab.
Click Messaging > Edit details.
On the Edit messaging configuration dialog, select the Webhook, TwiML Bin, Function, Studio Flow, Proxy Service option.
Under How do you want to set up your primary method?, select Webhook.
Paste your ngrok public URL in the URL box.
If your ngrok console shows Forwarding https://<your-app-name>.ngrok.dev, paste https://<your-app-name>.ngrok.dev to the URL box.
If you use the legacy Console, follow these steps:
If Twilio needs your compliance data, create a compliance profile first.
Click the Configuration details tab.
Click Messaging > Edit details.
On the Edit messaging configuration dialog, select the Webhook, TwiML Bin, Function, Studio Flow, Proxy Service option.
Under How do you want to set up your primary method?, select Webhook.
Paste your ngrok public URL in the URL box.
If your ngrok console shows Forwarding https://<your-app-name>.ngrok.dev, paste https://<your-app-name>.ngrok.dev to the URL box.
If you use the legacy Console, follow these steps:
If you don't have any phone numbers, click Buy a number.
Click Configure next to your phone number. Twilio opens the Phone Number page with the Configure tab selected.
Go to the Voice Configuration section.
In the A call comes in dropdown menu, select Webhook.
In the URL box, paste your ngrok public URL.
For example, https://<your-app-name>.ngrok.dev).
Leave the other boxes and menus with their default values.
At the end of the page, click Save configuration.
With your Sinatra server and ngrok running, call your Twilio phone number. You hear the text-to-speech message defined in answer_call.rb.
Result
After following this guide, you can make an outbound call and handle inbound calls programmatically with Twilio Programmable Voice. You can confirm it works by running your server-side script to trigger an outbound call to your personal device or by calling your Twilio number to hear the <Say> text-to-speech response.
Next steps
To build on what you've learned in this guide, consult the following guides: