Skip to content

Instantly share code, notes, and snippets.

@mseeks
Created February 8, 2024 02:24
Show Gist options
  • Save mseeks/83d539d2500a9b0ae39b03d458c280ca to your computer and use it in GitHub Desktop.
Save mseeks/83d539d2500a9b0ae39b03d458c280ca to your computer and use it in GitHub Desktop.
Python code snippet for fetching an audio file URL from an MMS message using Twilio's Python SDK.
from twilio.rest import Client
# Twilio credentials
account_sid = 'your_account_sid'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)
# Fetch a specific message by SID
message_sid = 'SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
message = client.messages(message_sid).fetch()
# Extracting media URL from the message
# Note: Assumes the message contains only one media item
media_url = message.media.list()[0].uri
# Remove the '.json' at the end of the URL
media_url = media_url.replace('.json', '')
# Complete media URL
media_url_complete = f'https://api.twilio.com{media_url}'
print(media_url_complete)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment