Skip to content

Instantly share code, notes, and snippets.

@gspncr
Last active May 10, 2022 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gspncr/21af231f54e410f8033b76637f8b6705 to your computer and use it in GitHub Desktop.
Save gspncr/21af231f54e410f8033b76637f8b6705 to your computer and use it in GitHub Desktop.
Print to the console voice/message activity and your numbers. Take this information to look at the numbers you own without logged calls/messages.
TWILIO_ACCOUNT_SID=ACxxxxxxxxxx
TWILIO_AUTH_TOKEN=xxxxxxxxx
import os
from dotenv import load_dotenv
from twilio.rest import Client
load_dotenv()
# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
# Retrieve a list of the calls that have happened in our account
# and optionally provide a status and limit
calls = client.calls.list(status='completed', limit=20)
print ('\033[1;31mCalls \033[0m')
for record in calls:
call = client.calls(record.sid).fetch()
print('Call SID: ', record.sid, ' From: ',call.from_, ' Call End Time: ', call.end_time)
messages = client.messages.list(limit=20)
print ('\033[1;32mMessages \033[0m')
for record in messages:
if (record.direction == 'outbound-api'):
print('Message SID: ', record.sid, ' From: ', record.from_)
# Retrieve a list of the numbers our account has purchased
# and optionally provide a limit
incoming_phone_numbers = client.incoming_phone_numbers.list(limit=20)
print ('\033[1;34mNumbers \033[0m')
for record in incoming_phone_numbers:
print('Number SID: ', record.sid, ' Number: ', record.phone_number, ' Number Status: ', record.status, ' Number Friendly Name: ', record.friendly_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment