Emilio Garcia Emilio Garcia - 1 year ago 113
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()

So every 5 seconds, it lets me know how many messages I have. In
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 Source
for message in messages:
  print message.body
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download