8000 some initial work on queue twiml · thinkingserious/twilio-python@2e5f51c · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e5f51c

Browse files
committed
some initial work on queue twiml
1 parent ada3b2a commit 2e5f51c

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

tests/test_twiml.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,29 @@ def test_conf_end_conference(self):
332332
self.assertEqual(self.conf.get('endConferenceOnExit'), "true")
333333

334334

335+
class TestQueue(TwilioTest):
336+
337+
def setUp(self):
338+
r = Response()
339+
with r.dial() as dial:
340+
dial.queue("TestQueueAttribute", url="", method='GET')
341+
xml = r.toxml()
342+
343+
#parse twiml XML string with Element Tree and inspect
344+
#structure
345+
tree = ET.fromstring(xml)
346+
self.conf = tree.find(".//Dial/Queue")
347+
348+
def test_conf_text(self):
349+
self.assertEqual(self.conf.text.strip(), "TestQueueAttribute")
350+
351+
def test_conf_waiturl(self):
352+
self.assertEqual(self.conf.get('url'), "")
353+
354+
def test_conf_method(self):
355+
self.assertEqual(self.conf.get('method'), "GET")
356+
357+
335358
class TestDial(TwilioTest):
336359

337360
def testDial(self):
@@ -374,6 +397,14 @@ def testAddConference(self):
374397
r = self.strip(r)
375398
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Conference>My Room</Conference></Dial></Response>')
376399

400+
def test_add_queue(self):
401+
""" add a queue to a dial"""
402+
r = Response()
403+
d = r.dial()
404+
d.append(twiml.Queue("The Cute Queue"))
405+
r = self.strip(r)
406+
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Queue>The Cute Queue</Queue></Dial></Response>')
407+
377408
def test_add_empty_client(self):
378409
""" add an empty client to a dial"""
379410
r = Response()

twilio/twiml.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,20 +367,20 @@ class Dial(Verb):
367367
368368
:param action: submit the result of the dial to this URL
369369
:param method: submit to 'action' url using GET or POST
370-
:param int timeout: The number of seconds to waits for the called
370+
:param int timeout: The number of seconds to waits for the called
371371
party to answer the call
372-
:param bool hangupOnStar: Allow the calling party to hang up on the
372+
:param bool hangupOnStar: Allow the calling party to hang up on the
373373
called party by pressing the '*' key
374374
:param int timeLimit: The maximum duration of the Call in seconds
375375
:param callerId: The caller ID that will appear to the called party
376376
:param bool record: Record both legs of a call within this <Dial>
377377
"""
378378
GET = 'GET'
379379
POST = 'POST'
380-
nestables = ['Number', 'Conference', 'Client']
380+
nestables = ['Number', 'Conference', 'Client', 'Queue']
381381

382382
def __init__(self, number=None, **kwargs):
383-
super(Dial, self).__init__(**kwargs)
383+
super(Dial, self).__init__(**kwargs)
384384
if number and len(number.split(',')) > 1:
385385
for n in number.split(','):
386386
self.append(Number(n.strip()))
@@ -396,13 +396,32 @@ def number(self, number, **kwargs):
396396
def conference(self, name, **kwargs):
397397
return self.append(Conference(name, **kwargs))
398398

399+
def queue(self, name, **kwargs):
400+
return self.append(Queue(name, **kwargs))
401+
399402
def addNumber(self, *args, **kwargs):
400403
return self.number(*args, **kwargs)
401404

402405
def addConference(self, *args, **kwargs):
403406
return self.conference(*args, **kwargs)
404407

405408

409+
class Queue(Verb):
410+
"""Specify queue in a nested Dial element.
411+
412+
:param name: friendly name for the queue
413+
:param url: url to a twiml document that executes after a call is dequeued
414+
and 8047 before the call is connected
415+
:param method: HTTP method for url GET/POST
416+
"""
417+
GET = 'GET'
418+
POST = 'POST'
419+
420+
def __init__(self, name, **kwargs):
421+
super(Queue, self).__init__(**kwargs)
422+
self.body = name
423+
424+
406425
class Record(Verb):
407426
"""Record audio from caller
408427

0 commit comments

Comments
 (0)
0