本文整理汇总了Python中twilio.twiml.voice_response.VoiceResponse.redirect方法的典型用法代码示例。如果您正苦于以下问题:Python VoiceResponse.redirect方法的具体用法?Python VoiceResponse.redirect怎么用?Python VoiceResponse.redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twilio.twiml.voice_response.VoiceResponse
的用法示例。
在下文中一共展示了VoiceResponse.redirect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gather
# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import redirect [as 别名]
def gather():
"""Processes results from the <Gather> prompt in /voice"""
# Start our TwiML response
resp = VoiceResponse()
# If Twilio's request to our app included already gathered digits,
# process them
if 'Digits' in request.values:
# Get which digit the caller chose
choice = request.values['Digits']
# <Say> a different message depending on the caller's choice
if choice == '1':
resp.say('You selected sales. Good for you!')
return str(resp)
elif choice == '2':
resp.say('You need support. We will help!')
return str(resp)
else:
# If the caller didn't choose 1 or 2, apologize and ask them again
resp.say("Sorry, I don't understand that choice.")
# If the user didn't choose 1 or 2 (or anything), send them back to /voice
resp.redirect('/voice')
return str(resp)
示例2: voice
# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import redirect [as 别名]
def voice():
"""Respond to incoming phone calls with a menu of options"""
# Start our TwiML response
resp = VoiceResponse()
# If Twilio's request to our app included already gathered digits,
# process them
if 'Digits' in request.values:
# Get which digit the caller chose
choice = request.values['Digits']
# <Say> a different message depending on the caller's choice
if choice == '1':
resp.say('You selected sales. Good for you!')
return str(resp)
elif choice == '2':
resp.say('You need support. We will help!')
return str(resp)
else:
# If the caller didn't choose 1 or 2, apologize and ask them again
resp.say("Sorry, I don't understand that choice.")
# Start our <Gather> verb
gather = Gather(num_digits=1)
gather.say('For sales, press 1. For support, press 2.')
resp.append(gather)
# If the user doesn't select an option, redirect them into a loop
resp.redirect('/voice')
return str(resp)
示例3: complete
# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import redirect [as 别名]
def complete():
params, campaign = parse_params(request)
i = int(request.values.get('call_index', 0))
if not params or not campaign:
abort(400)
(uid, prefix) = parse_target(params['targetIds'][i])
(current_target, cached) = Target.get_or_cache_key(uid, prefix)
call_data = {
'session_id': params['sessionId'],
'campaign_id': campaign.id,
'target_id': current_target.id,
'call_id': request.values.get('CallSid', None),
'status': request.values.get('DialCallStatus', 'unknown'),
'duration': request.values.get('DialCallDuration', 0)
}
try:
db.session.add(Call(**call_data))
db.session.commit()
except SQLAlchemyError:
current_app.logger.error('Failed to log call:', exc_info=True)
resp = VoiceResponse()
if call_data['status'] == 'busy':
play_or_say(resp, campaign.audio('msg_target_busy'),
title=current_target.title,
name=current_target.name,
lang=campaign.language_code)
# TODO if district offices, try another office number
i = int(request.values.get('call_index', 0))
if i == len(params['targetIds']) - 1:
# thank you for calling message
play_or_say(resp, campaign.audio('msg_final_thanks'),
lang=campaign.language_code)
else:
# call the next target
params['call_index'] = i + 1 # increment the call counter
calls_left = len(params['targetIds']) - i - 1
play_or_say(resp, campaign.audio('msg_between_calls'),
calls_left=calls_left,
lang=campaign.language_code)
resp.redirect(url_for('call.make_single', **params))
return str(resp)
示例4: schedule_parse
# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import redirect [as 别名]
def schedule_parse():
"""
Handle schedule response entered by user
Required Params: campaignId, Digits
"""
params, campaign = parse_params(request)
resp = VoiceResponse()
if not params or not campaign:
abort(400)
schedule_choice = request.values.get('Digits', '')
if current_app.debug:
current_app.logger.debug(u'entered = {}'.format(schedule_choice))
if schedule_choice == "1":
# schedule a call at this time every day
play_or_say(resp, campaign.audio('msg_schedule_start'),
lang=campaign.language_code)
scheduled = True
schedule_created.send(ScheduleCall,
campaign_id=campaign.id,
phone=params['userPhone'],
location=params['userLocation'])
elif schedule_choice == "9":
# user wishes to opt out
play_or_say(resp, campaign.audio('msg_schedule_stop'),
lang=campaign.language_code)
scheduled = False
schedule_deleted.send(ScheduleCall,
campaign_id=campaign.id,
phone=params['userPhone'])
else:
# because of the timeout, we may not have a digit
scheduled = False
params['scheduled'] = scheduled
resp.redirect(url_for('call._make_calls', **params))
return str(resp)
示例5: location_parse
# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import redirect [as 别名]
def location_parse():
"""
Handle location entered by the user.
Required Params: campaignId, Digits
"""
params, campaign = parse_params(request)
if not params or not campaign:
abort(400)
location = request.values.get('Digits', '')
# Override locate_by attribute so locate_targets knows we're passing a zip
# This allows call-ins to be made for campaigns which otherwise use district locate_by
campaign.locate_by = LOCATION_POSTAL
# Skip special, because at this point we just want to know if the zipcode is valid
located_target_ids = locate_targets(location, campaign, skip_special=True)
if current_app.debug:
current_app.logger.debug(u'entered = {}'.format(location))
if not located_target_ids:
resp = VoiceResponse()
play_or_say(resp, campaign.audio('msg_invalid_location'),
lang=campaign.language_code)
return location_gather(resp, params, campaign)
params['userLocation'] = location
call_session = Session.query.get(params['sessionId'])
if not call_session.location:
call_session.location = location
db.session.add(call_session)
db.session.commit()
resp = VoiceResponse()
resp.redirect(url_for('call._make_calls', **params))
return str(resp)
示例6: schedule_prompt
# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import redirect [as 别名]
def schedule_prompt(params, campaign):
"""
Prompt the user to schedule calls
"""
if not params or not campaign:
abort(400)
resp = VoiceResponse()
g = Gather(num_digits=1, timeout=3, method="POST", action=url_for("call.schedule_parse", **params))
existing_schedule = ScheduleCall.query.filter_by(campaign_id=campaign.id, phone_number=params['userPhone']).first()
if existing_schedule and existing_schedule.subscribed:
play_or_say(g, campaign.audio('msg_alter_schedule'), lang=campaign.language_code)
else:
play_or_say(g, campaign.audio('msg_prompt_schedule'), lang=campaign.language_code)
resp.append(g)
# in case the timeout occurs, we need a redirect verb to ensure that the call doesn't drop
params['scheduled'] = False
resp.redirect(url_for('call._make_calls', **params))
return str(resp)
示例7: VoiceResponse
# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import redirect [as 别名]
from twilio.twiml.voice_response import Redirect, VoiceResponse
response = VoiceResponse()
response.redirect('../nextInstructions')
print(response)
示例8: VoiceResponse
# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import redirect [as 别名]
from twilio.twiml.voice_response import Gather, Redirect, VoiceResponse, Say
response = VoiceResponse()
gather = Gather(action='/process_gather.php', method='GET')
gather.say('Enter something, or not')
response.append(gather)
response.redirect('/process_gather.php?Digits=TIMEOUT', method='GET')
print(response)
示例9: VoiceResponse
# 需要导入模块: from twilio.twiml.voice_response import VoiceResponse [as 别名]
# 或者: from twilio.twiml.voice_response.VoiceResponse import redirect [as 别名]
from twilio.twiml.voice_response import Redirect, VoiceResponse
response = VoiceResponse()
response.redirect('http://pigeons.com/twiml.xml', method='POST')
print(response)