Easy SMS and MMS chat with Twilio in python - Nerd Platoon Easy SMS and MMS chat with Twilio in python - Nerd Platoon

Twilio is one of the communication platforms used by thousands of businesspeople and many developers worldwide to build efficient customer experience. It helps in interacting with the customers via Calls or SMS.

Buy a Twilio Number with SMS and MMS capabilities.

After creating an account on Twilio, one can easily buy a Twilio number with SMS and MMS capabilities by simply checking the SMS and MMS button. Then clicking the buy option, we are ready to test that Twilio number for SMS.
Access the “Buy Number Page” in Console.
This is found in the Console under Develop > Phone Numbers > Manage > Buy a Number.

Twilio installation

Python provides a library called ‘Twilio’ that provides REST API services to send a message. One can install a Twilio library with a python helper library called pip with the ‘”pip install twilio” command.
The Script for sending a message via Twilio is as follows.

“from twilio.rest import Client
client = Client(account_sid, auth_token)
message = client.messages .create(
body=’This is a test message’,
from_=twilio_number,
to=reciver_number
)”

Send SMS to multiple recipient

Replace account_sid and auth_token with your Twillio’s unique values. twilio_number is a number used for sending the SMS. Similarly, reciever_number is the one receiving a message. Sending a message to multiple recipients can be achieved by

“numbers_to_message = [number1, number2, number3]
for number in numbers_to_message:
client.messages.create(
body=’Hello from my Twilio number!’,
from_=sender_twilio_number,
to=number
)
“.

Send MMS via Twilio

Now let’s discuss sending the MMS via Twilio. To add the media in our Twilio-powered text message, we need to add an extra argument named “media_url” as

from twilio. rest import Client
client = Client(account_sid, auth_token)
message = client.messages .create(
body=’This is a test message’,
media_url=[path_to_the_media]
from_=twilio_number,
to=reciver_number
)
“.