Created
August 22, 2016 17:21
-
-
Save atbaker/7da264b194f57dda36d17526510aae07 to your computer and use it in GitHub Desktop.
Identify Twilio SMS recipients who have STOP'd your number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
See also: | |
https://support.twilio.com/hc/en-us/articles/223134027-Twilio-support-for-STOP-BLOCK-and-CANCEL-SMS-STOP-filtering- | |
""" | |
# Download the Python helper library from twilio.com/docs/python/install | |
from twilio.rest import TwilioRestClient | |
# Your Account Sid and Auth Token from twilio.com/user/account | |
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
auth_token = "your_auth_token" | |
client = TwilioRestClient(account_sid, auth_token) | |
# A list of message objects with the properties described above | |
messages = client.messages.list(To='your_twilio_number') | |
STOP_KEYWORDS = ('STOP', 'STOPALL', 'UNSUBSCRIBE', 'CANCEL', 'END', 'QUIT') | |
stopped_numbers = [message.from_ for message in messages if message.body.upper() in STOP_KEYWORDS] | |
print(stopped_numbers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment