You can add an image to your message using the parameter media_url
.
# Download the twilio-python library from http://twilio.com/docs/libraries
from twilio.rest import TwilioRestClient
# Find these values at https://twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXX"
auth_token = "YYYYYYYYYYYYYYYYYY"
client = TwilioRestClient(account_sid, auth_token)
message = client.messages.create(
to="+12316851234",
from_="TWILIO_NUMBER",
body="Hello there, StackOverflow!",
media_url=[
'https://demo.twilio.com/owl.png',
'https://demo.twilio.com/logo.png'])
To send your first SMS with Twilio and Python you'll just need the Twilio-Python helper library to get started.
# Download the twilio-python library from http://twilio.com/docs/libraries
from twilio.rest import TwilioRestClient
# Find these values at https://twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXX"
auth_token = "YYYYYYYYYYYYYYYYYY"
client = TwilioRestClient(account_sid, auth_token)
message = client.messages.create(to="+12316851234", from_="TWILIO_NUMBER",
body="Hello there, StackOverflow!")
Twilio help build apps that communicate with everyone in the world. Voice & Video, Messaging and Authentication APIs for every application.
You can get an API key for free.
To send a message through Twilio, your application needs to make an HTTP POST request to Twilio with the following things:
To send an SMS, make an HTTP POST request to the Messages resource.
POST https://api.twilio.com/20xx-xx-xx/Accounts/xxxxxxx/Messages
Below is an example code to show how sending messeges with Twilio API will work.
# Download the twilio-python library from http://twilio.com/docs/libraries
from twilio.rest import TwilioRestClient
# Find these values at https://twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXX"
auth_token = "YYYYYYYYYYYYYYYYYY"
client = TwilioRestClient(account_sid, auth_token)
message = client.messages.create(
to = "+12316851234",
from_ = "+15555555555",
body = "Hello there!"
)
If the Twilio number supports MMS, then you can send and receive MMS also.
Below is code to send MMS through Twilio API.
message = client.messages.create(
to = "+12316851234",
from_ = "+15555555555",
body = "Hello there!",
media_url=[
'https://demo.twilio.com/owl.png',
'https://demo.twilio.com/logo.png'
])
Parameter | Details |
---|---|
to (str) | The destination phone number. |
from_ (str) | The phone number sending this message (must be a verified Twilio number) |
body (str) | The message you want to send, limited to 160 characters. |
status_callback | A URL that Twilio will POST to when your message is processed. |
application_sid (str) | The 34 character sid of the application Twilio should use to handle this phone call. |