def test_queue(self): d = Dial() d.queue('TestQueueAttribute', url='', method='GET') r = VoiceResponse() r.append(d) assert_equal( self.strip(r), '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Queue method="GET" url="">TestQueueAttribute</Queue></Dial></Response>' )
def test_add_queue(self): """ add a queue to a dial """ d = Dial() d.queue('The Cute Queue') r = VoiceResponse() r.append(d) assert_equal( self.strip(r), '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Queue>The Cute Queue</Queue></Dial></Response>' )
def voice(): """Respond to incoming phone calls with a menu of options""" pprint(request.values) # kept for debugging purposes resp = VoiceResponse() agent = AGENTS.get(request.values.get("Caller")) if "Digits" in request.values: choice = request.values["Digits"] if agent: if choice == "1": resp.say("You will get the next call.") dial = Dial() dial.queue(call_queue.name) resp.append(dial) else: resp.say("Sorry, I don't understand that choice.") else: queue_size = call_queue.size() if agent: gather = Gather(num_digits=1) gather.say( f"Hello, {agent}. There are {queue_size} callers in the queue, press 1 to answer the next call" ) resp.append(gather) else: # customer resp.say( f"There are {queue_size} people ahead of you. An agent will talk to you soon." ) # in case you want to play a message before # resp.play( # 'http://com.twilio.sounds.music.s3.amazonaws.com/MARKOVICHAMP-Borghestral.mp3' # ) resp.enqueue(call_queue.name) # wait_url = 'http://demo.twilio.com/docs/voice.xml' # If the caller doesn't select an option, redirect them into a loop resp.redirect("/voice") return str(resp)
# Download the Python helper library from twilio.com/docs/python/install from twilio.twiml.voice_response import VoiceResponse, Dial r = VoiceResponse() r.say("You will now be connected to the first caller in the queue.") d = Dial() d.queue("Queue Demo") r.append(d) r.redirect('http://example.org') print(str(r))
from twilio.twiml.voice_response import Dial, Queue, VoiceResponse response = VoiceResponse() dial = Dial() dial.queue('support', url='about_to_connect.xml') response.append(dial) print(response)