本文整理汇总了Python中twilio.twiml.Response.redirect方法的典型用法代码示例。如果您正苦于以下问题:Python Response.redirect方法的具体用法?Python Response.redirect怎么用?Python Response.redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twilio.twiml.Response
的用法示例。
在下文中一共展示了Response.redirect方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_connect
# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import redirect [as 别名]
def handle_connect(request):
recipient_number = request.POST.get('Digits', '')
r = Response()
if 'visitor' in request.session:
try:
recipient = Visitor.objects.get(access_code=recipient_number)
request.session['recipient'] = {
'id': recipient.id,
'name': recipient.user.first_name,
'number': recipient.access_code
}
# record a message
r.say(
'The person you tried to call is unavailable. Please leave a message')
r.record(maxLength=30, action=reverse(
'twiliorouter:handle_record')
)
except Visitor.DoesNotExist:
request.session['welcome_message'] = 'Number not recognised'
r.redirect(reverse('twiliorouter:connect'))
else:
request.session[
'welcome_message'] = 'You need to enter your phone number'
r.redirect(reverse('twiliorouter:welcome'))
return r
示例2: gather
# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import redirect [as 别名]
def gather(request):
logger.debug("Calling gather")
d = request.GET.get("Digits")
logger.debug("Digit Pressed= %s" % d)
try:
r = Response()
if d == "1":
r.say("You pressed 1")
try:
api = twitter.Api()
statuses = api.GetUserTimeline("diarmuid")
r.say(statuses[0].text)
except Exception, ex:
logger.debug(ex)
r.say("Error getting twitter results")
r.redirect(reverse("calls_hello"))
return r
elif d == "2":
r.say("You pressed 2")
r.say("Record your message after the tone.")
r.record(maxLength="10", action=reverse("calls_record"))
return r
示例3: welcome
# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import redirect [as 别名]
def welcome(request, message=''):
if message == '':
message = 'Welcome to Hill Valley.'
if 'welcome_message' in request.session:
message = request.session['welcome_message']
del request.session['welcome_message']
r = Response()
r.say(message)
# if we are logged in return options, otherwise ask for login
if 'visitor' in request.session:
r.redirect(reverse('twiliorouter:welcome_options'))
else:
# try to login
r.redirect(reverse('twiliorouter:login'))
return r
示例4: record
# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import redirect [as 别名]
def record(request):
"""A simple test view that returns a HttpResponse object."""
r = Response()
try:
u = request.POST["RecordingUrl"]
r.say("Thanks for the message... take a listen to your message .")
r.play(u)
r.say("Goodbye.")
r.redirect(reverse("calls_hello"))
return r
except Exception, ex:
logger.debug(ex)
r.redirect(reverse("calls_hello"))
示例5: connect
# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import redirect [as 别名]
def connect(request):
# we are trying to connect to another account
r = Response()
if 'visitor' in request.session:
with r.gather(
numDigits=6,
timeout=10,
finishOnKey='*',
action=reverse('twiliorouter:handle_connect'), method='POST'
) as g:
g.say(
'please enter the 6 digit number you want to connect to'
)
else:
request.session['welcome_message'] = ''
r.redirect(reverse('twiliorouter:welcome'))
return r
示例6: handle_login
# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import redirect [as 别名]
def handle_login(request):
access_code = request.POST.get('Digits', '')
r = Response()
try:
visitor = Visitor.objects.get(access_code=access_code)
request.session['visitor'] = {
'id': visitor.id,
'name': visitor.user.first_name,
'number': visitor.access_code
}
# this was a valid user code - redirect to inbox
r.redirect(
reverse('twiliorouter:twilio_messages', args=[visitor.access_code]))
return r
except Visitor.DoesNotExist:
request.session['welcome_message'] = 'Number not recognised'
r.redirect(reverse('twiliorouter:welcome'))
return r
示例7: handle_opt
# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import redirect [as 别名]
def handle_opt():
response = Response()
digit = request.form["Digits"]
opt = request.args.get("opt_" + digit, None)
if opt is None:
response.say(err_say)
response.redirect("{}?{}".format(request.base_url, request.query_string))
return str(response)
opt_args = opt.split(":")
if opt_args[0] == "Call":
response.dial(opt_args[2])
elif opt_args[0] == "Info":
response.say(opt_args[2], voice=voice)
response.say(end_say, voice=voice)
return str(response)
示例8: notify_call
# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import redirect [as 别名]
def notify_call(request, notification_uuid):
r = Response()
try:
notification = Notification.objects.get(uuid=notification_uuid)
except Notification.DoesNotExist:
return r
r.say("This is an oncaller notification.")
message = notification.message
if message:
r.say(message, loop=2)
#duke!
r.play('http://dev.oncallr.com/static/audio/b2w.mp3')
r.pause(length=1)
r.say("Hit 1 to acknowledge, 2 to reject.", voice="woman")
r.gather(action="http://www.oncallr.com/notification/call/response/{0}/".format(notification_uuid), method="POST", numDigits=1, timeout=2, finishOnKey=None)
r.redirect(url="http://www.oncallr.com/notification/call/response/{0}/".format(notification_uuid), method="POST")
return r
示例9: handle_response_message
# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import redirect [as 别名]
def handle_response_message(request):
digits = request.POST.get('Digits', '')
to_number = request.POST.get('To', '')
call_sid = request.POST.get('CallSid', '')
twilio_response = Response()
return_message = get_fizzbuzz_message(int(digits))
# if digits == '1':
# twilio_response.play('http://bit.ly/phaltsw')
#
# if digits == '2':
# number = request.POST.get('From', '')
# twilio_response.say('A text message is on its way')
# twilio_response.sms('You looking lovely today!', to=number)
twilio_response.say(return_message)
update_call_record(to_number, call_sid, str(digits))
twilio_response.redirect('/ring/')
return twilio_response
示例10: twilio_messages
# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import redirect [as 别名]
def twilio_messages(request):
# this endpoint is used to return the twiml response for the inbox count
r = Response()
if 'visitor' in request.session:
visitor = request.session['visitor']
# get active messages for this user
# todo - only return active messages (i.e. not expired)
num_new_messages = 0
num_old_messages = 0
messages = Message.objects.filter(recipient__id=visitor['id'])
for message in messages:
if message.accessed == False:
num_new_messages += 1
else:
num_old_messages += 1
if num_new_messages > 0:
r.say('user inbox')
else:
r.say('you have no new messages')
else:
request.session['welcome_message'] = 'Number not recognised'
r.redirect(reverse('twiliorouter:welcome'))
return r
示例11: handle_welcome_options
# 需要导入模块: from twilio.twiml import Response [as 别名]
# 或者: from twilio.twiml.Response import redirect [as 别名]
def handle_welcome_options(request):
if 'visitor' in request.session:
visitor = request.session['visitor']
choice = int(request.POST.get('Digits', '0'))
r = Response()
if choice == 1:
# user wants to listen to their message - try to login
r.redirect(
reverse('twiliorouter:twilio_messages'), args=[visitor['number']])
elif choice == 2:
# user wants to contact another user
r.redirect(reverse('twiliorouter:connect'))
else:
request.session['welcome_message'] = 'Option not available'
r.redirect(reverse('twiliorouter:welcome'))
else:
request.session['welcome_message'] = 'Option not available'
r.redirect(reverse('twiliorouter:welcome'))
return r