-
Notifications
You must be signed in to change notification settings - Fork 2
/
sms.py
34 lines (29 loc) · 890 Bytes
/
sms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import twilio
from flask import Markup
API_VERSION = '2010-04-01'
ACCOUNT_SID = 'AC...'
ACCOUNT_TOKEN = '...'
# Outgoing Caller ID previously validated with Twilio
CALLER_ID = 'NNNNNNNNNN'
account = twilio.Account(ACCOUNT_SID, ACCOUNT_TOKEN)
def build_sms(text):
return """<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Sms>%s</Sms>
</Response>
""" % (Markup.escape(text))
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', 'w').write(e.read())