Emilio Garcia Emilio Garcia - 1 month ago 12
Python Question

Store SMS body as string in Python with Twilio

I'd like to get the body of an SMS message sent to my Twilio number saved as a string in my python program. I can't find any documentation on how to do this. I have a program that lets me know when a new message is sent, but I don't know how to access it.

from twilio.rest import TwilioRestClient
from TwilioPasswords import *
import time

while True:
client = TwilioRestClient(account_sid, auth_token)
messages = client.messages.list()
print(len(messages))
time.sleep(5)


So every 5 seconds, it lets me know how many messages I have. In
messages
I get a list of data like
<twilio.rest.resources.messages.Message object at 0x03462DB0>
. I want to get the body of that message. How can I do this?

Answer
for message in messages:
  print message.body