def confirm_call(request, notification_uuid): r = Response() try: notification = Notification.objects.get(uuid=notification_uuid) except Notification.DoesNotExist: return r digits = request.POST.get("Digits", None) call_sid = request.POST.get("CallSid", None) notification.recipient_status = REJECTED if digits is None: r.say("No response detected. Assuming rejection. Good bye.", voice="woman") elif '1' in digits: r.say("You have acknowledged this notification. Thank You.", voice="woman") notification.recipient_status = ACK elif '2' in digits: r.say("You have rejected this notification. Good bye.", voice="woman") else: r.say("Invalid Selection. Rejecting Response. Good bye.", voice="woman") r.hangup() notification.save() return r
def dispatch(self, request, *args, **kwargs): print(request.GET) entry = get_call_request(CallEntry, **kwargs) status = request.GET['DialCallStatus'] resp = Response() if status in ['no-answer', 'failed']: entry.fail() next_entry = entry.request.get_entry() if request.GET.get('client', None) == 'voximplant': if next_entry is None: return JsonResponse({'next': 'hangup'}) data = { 'action': get_full_url(next_entry.get_absolute_url()), 'timeout': settings.CALLBACK_MANAGER_CALL_TIMEOUT, 'phones': [ phone.number for phone in next_entry.phones.filter( phone_type='phone') ], } return JsonResponse(data) if next_entry is None: resp.hangup() else: dial = resp.dial( callerId=next_entry.request.right_phone, action=get_full_url(next_entry.get_absolute_url()), method='GET', record=True, timeout=settings.CALLBACK_MANAGER_CALL_TIMEOUT) # TODO: refactor repeating for phone in entry.phones.all(): if phone.phone_type == 'sip': dial.sip('sip:' + phone.number) else: dial.number(phone.number) elif status == 'completed': entry.record_url = request.GET.get('RecordingUrl', None) entry.duration = request.GET.get('RecordingDuration', 0) entry.success() resp.hangup() else: raise Exception('Wrong status: %s' % status) return HttpResponse(str(resp), content_type='text/xml')
def dispatch(self, request, *args, **kwargs): print(request.GET) call_request = get_call_request(CallbackRequest, **kwargs) entry = call_request.get_entry() if request.GET.get('client', None) == 'voximplant': if entry is None: return JsonResponse({'next': 'hangup'}) data = { 'intro': settings.CALLBACK_INTRO_MP3, 'action': get_full_url(entry.get_absolute_url()), 'timeout': settings.CALLBACK_MANAGER_CALL_TIMEOUT, 'phones': [ phone.number for phone in entry.phones.filter(phone_type='phone') ], } return JsonResponse(data) resp = Response() if entry is None: resp.hangup() else: intro_url = settings.CALLBACK_INTRO_MP3 if intro_url is not None: resp.play(intro_url) dial = resp.dial(callerId=call_request.right_phone, action=get_full_url(entry.get_absolute_url()), method='GET', record=True, timeout=settings.CALLBACK_MANAGER_CALL_TIMEOUT) # TODO: add statusCallback and statusCallbackMethod # for every request, so we can mark phone who really answered the call # https://www.twilio.com/docs/api/twiml/number#attributes for phone in entry.phones.all(): if phone.phone_type == 'sip': dial.sip('sip:' + phone.number) else: dial.number(phone.number) return HttpResponse(str(resp), content_type='text/xml')
def get_phone_score(request): r = Response() team_id = request.POST['Digits'] try: team = Team.objects.get(pk=team_id) scores = Score.objects.filter(team=team) r.say("Scores for team, "+team.name,voice='woman',language='en-gb') r.pause(length=2) for score in scores: r.say('For Event "'+score.event.name + '", You have ' + str(score.score) + ' points. ',voice='woman',language='en-gb') r.pause(length=1) r.say("Thank you for calling. Goodbye!",voice='woman',language='en-gb') r.hangup() except Team.DoesNotExist: r.say("We're sorry, The team number entered does not exist.") return r
def twilio_call_input(request, calllog_id): call_log = get_object_or_404(CallLog, id=int(calllog_id)) digit = request.POST["Digits"] call_log.log["input"] = dict(request.POST) call_log.log["input"]["_request"] = get_request_log_info(request) resp = TwilioResponse() if digit != "1": # basically an abuse report call_log.log["input"]["response"] = "did-not-request-call" resp.say( "We apologize for the inconvenience. Call 202-558-7227 or visit w w w dot gov track dot u s to report abuse. Good bye." ) resp.hangup() elif settings.DEBUG: resp.say("Site is in debug mode. Call cancelled.") resp.hangup() else: phone = "+1" + "".join( c for c in call_log.target.phone if unicode.isdigit(c)) call_log.log["input"]["response"] = "continue" call_log.log["input"]["transfer_to"] = phone resp.say("Okay. Hold on.") resp.dial( phone, action=request.build_absolute_uri( "/poll/_twilio/call-transfer-end/" + str(call_log.id)), timeout=30, callerId=request.POST["To"], record=True, ) call_log.status = "connecting" call_log.save() return resp
def twilio_call_input(request, call_id): report = get_object_or_404(WhipReport, id=int(call_id)) digit = request.POST["Digits"] report.call_log["input"] = dict(request.POST) report.call_log["input"]["_request"] = get_request_log_info(request) resp = TwilioResponse() if digit != "1": # basically an abuse report report.call_log["input"]["response"] = "did-not-request-call" resp.say("We apologize for the inconvenience. Call 202-558-7227 or visit w w w dot gov track dot u s to report abuse. Good bye.") resp.hangup() elif settings.DEBUG: resp.say("Site is in debug mode. Call cancelled.") resp.hangup() else: phone = "+1" + "".join(c for c in report.target.phone if unicode.isdigit(c)) report.call_log["input"]["response"] = "continue" report.call_log["input"]["transfer_to"] = phone resp.say("Okay. Hold on.") resp.dial( phone, action=build_twilio_callback_url(request, report, "call-transfer-end"), timeout=30, callerId=request.POST["To"], record=True, ) report.call_status = "connecting" report.save() return resp