Get message content from Twilio Message

118 Views Asked by At

Im trying to read the message body of a twilio message. I am able to read the message.to and the message.from_ but I cant seem to figure out how to get the body. Below is my code. I purposely removed my credentials.

# Download the helper library from https://www.twilio.com/docs/python/install
from twilio.rest import Client


# Your Account Sid and Auth Token from twilio.com/console
# DANGER! This is insecure. See http://twil.io/secure
account_sid = "AC#############################"
auth_token = "1##########################3"
client = Client(account_sid, auth_token)


# Get Message

message = client.messages('SM17ded763ce04f2cbbd343a39a243df').fetch()

print(message.to)
print(message.from_)

2

There are 2 best solutions below

0
Alan On

Does print(message.body) not work?

0
lizziepika On

Twilio developer evangelist here.

You can get the body of the message with message.body.

Let me know if this helps at all! <3