Created
April 30, 2011 19:48
-
-
Save jvimal/949939 to your computer and use it in GitHub Desktop.
Sending SMS using Twilio
This file contains 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
# Add it to sms.py | |
API_VERSION = '2010-04-01' | |
# Check your account info | |
ACCOUNT_SID = 'AC...' | |
ACCOUNT_TOKEN = '...' | |
# Sandbox number or the number you have asked users to call | |
CALLER_ID = 'NNNNNNNNNN' | |
account = twilio.Account(ACCOUNT_SID, ACCOUNT_TOKEN) | |
def send_sms(to, text): | |
"""We use Twilio's python libraries to send SMS. Taken directly | |
from: | |
https://github.com/twilio/twilio-python/blob/master/examples/example-rest.py""" | |
global account | |
d = { | |
"From" : CALLER_ID, | |
"To" : to, | |
"Body" : text | |
} | |
try: | |
account.request('/%s/Accounts/%s/SMS/Messages' % \ | |
(API_VERSION, ACCOUNT_SID), "POST", d) | |
except Exception, e: | |
open('error.log', 'a').write(e.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment