Skip to content

Instantly share code, notes, and snippets.

@jvimal
Created April 30, 2011 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvimal/949939 to your computer and use it in GitHub Desktop.
Save jvimal/949939 to your computer and use it in GitHub Desktop.
Sending SMS using Twilio
# 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