Twilio CLI Guide


If you have been following the steps in Extreme Privacy, you might possess VOIP telephone service through Twilio. In the book, I offer ways to push SMS text messages to email, but that does not allow you to send messages, fetch voicemail, or clean up your account. The VoIPSuite app is an option, but requires your to configure multiple cloud-based providers and requires a "middle man" to function. Some people want a direct option for their account with Twilio. The following steps supplement the book as an account access alternative. I will assume you have already established paid service through Twilio and you are using your desired application(s) for calls.

First, you must install the Twilio CLI software to your computer. This should only be a secure and trusted machine to which only you have access.

Linux: Execute the following Terminal commands:

    wget -qO- https://twilio-cli-prod.s3.amazonaws.com/twilio_pub.asc \
    | sudo apt-key add -
    sudo touch /etc/apt/sources.list.d/twilio.list
    echo 'deb https://twilio-cli-prod.s3.amazonaws.com/apt/ /' \
    | sudo tee /etc/apt/sources.list.d/twilio.list
    sudo apt update
    sudo apt install -y twilio
macOS: Use Brew to install.

    brew tap twilio/brew && brew install twilio
Windows: Download the executable:

    https://runtime-cli-redirect-6533.twil.io/redirect-to-github?ext=.exe
Once installed, execute twilio login within Terminal or Command Prompt. This will ask for your Twilio SID and Token, which can be found in your portal. When prompted, provide a name of CLI.Finally, execute twilio profiles:use CLI. This generates the appropriate configuration file which tells your computer to use this profile with the provided credentials for all future commands. You can now interact with the Twilio CLI using the following commands.

twilio phone-numbers:list displays your current numbers in your Twilio account. These are the numbers available for use.

twilio api:core:calls:list displays all voice call records stored in your log files. We will use this later to delete these.

twilio api:core:messages:list --properties="sid,from,body" displays all SMS text messages stored within your account. We will use this later to delete these. A sample is below.

SM76xxxxx +17025551212 This is a test SMS

This displays the SID of the message, the number (from or to), and the message.

twilio api:core:recordings:list displays all voicemail recordings stored within your account. We will use this later to delete these.

twilio api:core:transcriptions:list displays all voicemail transcriptions stored within your account. We will use this later to delete these.

twilio api:core:messages:create --to +17025551212 --from +12025551212 --body "Call me" -o json creates an outgoing SMS text message of "Call me" to a number from your chosen Twilio number.

If you have an audio voicemail message in your account, you can download it with wget https://api.twilio.com/2010-04-01/Accounts/ACxxxxx/Recordings/SID. Make sure you replace ACxxxxx with your own account number and SID with the value presented with the previous query.

twilio api:core:calls:remove --sid xxx deletes Twilio's record of a call. Replace xxx with the SID of the call presented with the previous command.

twilio api:core:messages:remove --sid xxx deletes Twilio's record of a text message. Replace xxx with the SID of the message presented with the previous command.

twilio api:core:recordings:remove --sid xxx deletes Twilio's copy of a voicemail file. Replace xxx with the SID of the recording presented with the previous command.

twilio api:lookups:v1:phone-numbers:fetch --phone-number +12025551212 --type carrier --type caller-name -o json displays the caller ID data associated with a specific number. This often identifies names associated with cellular and VoIP numbers.

You could memorize these commands and type them when you need them, or create a custom script which would prompt your for data. The following abbreviated script would work in Linux or macOS with Twilio SMS messages. Save this text as twilio.sh and be sure to make the file executable within the properties.

#!/bin/bash
cd ~/Downloads
clear
COLUMNS=12
PS3='Selection: '
options=("Fetch Numbers" "Fetch Messages" "Send Messages" "Delete Messages")
select opt in "${options[@]}"
do
case $opt in
"Fetch Numbers")
twilio phone-numbers:list
;;
"Fetch Messages")
twilio api:core:messages:list --properties="sid,from,body"
;;
"Send Messages")
echo "From Number: "
read data1
echo "To Number: "
read data2
echo "Message: "
read data3
twilio api:core:messages:create --to +1$data2 --from +1$data1 --body "$data3"
;;
"Delete Messages")
echo "SID: "
read data
twilio api:core:messages:remove --sid $data
;;
esac
done

Execute the script and select the appropriate options. This sample could be used to display your Twilio numbers, send a SMS message, and delete the logs of your actions. My personal script includes many more options which you could configure within your own custom script. Below is an example of my menu within Linux.

I can now use this script to:

  • Display my Twilio numbers
  • Display my Twilio call logs
  • Delete Twilio call logs
  • Display my Twilio messages
  • Send Twilio SMS Messages
  • Delete Twilio message logs
  • Display Twilio voicemail files
  • Download Twilio voicemail files
  • Delete Twilio voicemail files
  • Display Twilio transcription files
  • Download Twilio transcription files
  • Delete Twilio transcription files
  • Display Twilio caller ID data for a number
  • Display RPV caller ID data for a number
  • Display OpenCNAM caller ID data for a number
  • Display DataAxle caller ID data for a number
  • Display Ekata caller ID data for a number
  • Display Spam data for a number
The effort taken today to customize your own script will save you hours in the future, and allow you to interact with your Twilio account via Terminal without the need to log into an online portal or rely on a third party. I use mine every day. It helps me quickly check messages, calls, and voicemail while ensuring that I am not leaving traces of my activities behind within Twilio's servers. The following video displays a partial script in use within a macOS system.

Privacy Book


Our latest (4th Edition) book on Extreme Privacy is now available. Click HERE for details.