8000 Added SMS support · isbo/twilio-python@cba65c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit cba65c8

Browse files
author
Kyle Conroy
committed
Added SMS support
1 parent 709cd8f commit cba65c8

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

MANIFEST

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
README.markdown
22
setup.py
33
twilio.py
4-
examples/example-rest.py
5-
examples/example-twiml.py
6-
examples/example-utils.py

examples/example-twiml.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
Record
1919
Pause
2020
Number
21+
Conference
22+
Sms
2123
"""
2224

2325
import twilio

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
setup(
33
name = "twilio",
44
py_modules = ['twilio'],
5-
version = "2.0.1",
5+
version = "2.0.2",
66
description = "Twilio API client and TwiML generator",
77
author = "Twilio",
88
author_email = "help@twilio.com",

twilio.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
OTHER DEALINGS IN THE SOFTWARE.
2424
"""
2525

26-
__VERSION__ = "2.0.1"
26+
__VERSION__ = "2.0.2"
2727

2828
import urllib, urllib2, base64, hmac
2929
from hashlib import sha1
@@ -166,6 +166,7 @@ def __init__(self, **kwargs):
166166
self.verbs = []
167167
self.attrs = {}
168168
for k, v in kwargs.items():
169+
if k == "sender": k = "from"
169170
if v: self.attrs[k] = quoteattr(str(v))
170171

171172
def __repr__(self):
@@ -224,6 +225,9 @@ def addDial(self, number=None, **kwargs):
224225

225226
def addRecord(self, **kwargs):
226227
return self.append(Record(**kwargs))
228+
229+
def addConference(self, **kwargs):
230+
return self.append(Conference(**kwargs))
227231

228232
class Response(Verb):
229233
"""Twilio response object.
@@ -233,7 +237,7 @@ class Response(Verb):
233237
def __init__(self, version=None, **kwargs):
234238
Verb.__init__(self, version=version, **kwargs)
235239
self.nestables = ['Say', 'Play', 'Gather', 'Record', 'Dial',
236-
'Redirect', 'Pause', 'Hangup']
240+
'Redirect', 'Pause', 'Hangup', 'Sms']
237241

238242
class Say(Verb):
239243
"""Say text
@@ -328,6 +332,26 @@ class Number(Verb):
328332
def __init__(self, number, sendDigits=None, **kwargs):
329333
Verb.__init__(self, sendDigits=sendDigits, **kwargs)
330334
self.body = number
335+
336+
class Sms(Verb):
337+
""" Send a Sms Message to a phone number
338+
339+
to: whom to send message to, defaults based on the direction of the call
340+
sender: whom to send message from.
341+
action: url to request after the message is queued
342+
method: submit to 'action' url using GET or POST
343+
statusCallback: url to hit when the message is actually sent
344+
"""
345+
GET = 'GET'
346+
POST = 'POST'
347+
348+
def __init__(self, msg, to=None, sender=None, method=None, action=None,
349+
statusCallback=None, **kwargs):
350+
Verb.__init__(self, action=action, method=method, to=to, sender=sender,
351+
statusCallback=statusCallback, **kwargs)
352+
if method and (method != self.GET and method != self.POST):
353+
raise TwilioException( \
354+
"Invalid method parameter, must be GET or POST")
331355

332356
class Conference(Verb):
333357
"""Specify conference in a nested Dial element.

0 commit comments

Comments
 (0)
0