Created
February 8, 2024 02:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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