0

Suppose I have this code which places all the message history between a twilio number and its recipients in an array. Is there a way to retrieve only the message history from all the recipients and not the sender (whom is I)

from twilio.rest import Client

account_sid = 'xxxx'
auth_token = 'xxxx'
client = Client(account_sid, auth_token)


text=[]
messages = client.messages.list()
for record in messages:
    print(record.body)
    text.append(record.body)

print(text)

1 Answers1

0

There are some examples of filter criteria with the above command, you can filter on to: to your specific Twilio number to just see that side of the conversation (via body key).

# Download the helper library from https://www.twilio.com/docs/python/install
from datetime import datetime
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 = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)

messages = client.messages.list(
                               to='+15558675310',
                               limit=20
                           )

for record in messages:
    print(record.sid)
Alan
  • 10,465
  • 2
  • 8
  • 9