def handle_third_response(request): digits = request.POST.get('Digits', '') twilio_response_three=Response() #twilio_response_three.say(digits) twilio_response_three.play('http://travellingscholar.com/ammi/message6.mp3') twilio_response_three.gather(action='respond4', numDigits=1) return twilio_response_three
def handle_response_digits(request): twilio_request = decompose(request) digits = twilio_request.digits twilio_response = Response() if digits == '2': # twilio_response.play('http://bit.ly/phaltsw') number = request.POST.get('From', '') twilio_response.say('A text message is on its way. Daaaaaaaaaaaaaaamn Daniel! Peace out yo') twilio_response.sms('Daaaaaaaaaaaaaaamn Daniel!', to=number) elif digits == '1': # twilio_response.play('http://bit.ly/phaltsw') # twilio_response.play('https://p.scdn.co/mp3-preview/934da7155ec15deb326635d69d050543ecbee2b4') # twilio_response.play('https://p.scdn.co/mp3-preview/934da7155ec15deb326635d69d050543ecbee2b4') twilio_response.play('https://demo.twilio.com/hellomonkey/monkey.mp3') # number = request.POST.get('From', '') # twilio_response.say('I got you bruh, sending you a text in a bit. PEACE!') # twilio_response.sms('You looking lovely today!', to=number) elif digits == "3": twilio_response.say("Record your monkey howl after the tone.") twilio_response.record(maxLength="5", action="/handle_recording") # If the caller pressed invalid input else: # twilio_response.say('Incorrect Number Pressed') return redirect("/gather") return twilio_response
def handle_third_response(request): digits = request.POST.get('Digits', '') twilio_response_three = Response() #twilio_response_three.say(digits) twilio_response_three.play( 'http://travellingscholar.com/ammi/message6.mp3') twilio_response_three.gather(action='respond4', numDigits=1) return twilio_response_three
def handle_fourth_response(request): digits = request.POST.get('Digits', '') number = request.POST.get('From','') twilio_response_four=Response() #twilio_response_four.say(digits) twilio_response_four.play('http://travellingscholar.com/ammi/message7a.mp3') twilio_response_four.sms('Your newborn will need lots of food to grow. The best food for your newborn is your breastmilk. Feeding her honey or ghee is harmful and a waste of your special milk.', to=number) return twilio_response_four
def echo(request): response = Response() if request.method == 'POST': response.play(request.POST['RecordingUrl']) else: response.say("Echo test", voice='woman') response.record() return response
def gather_digits(request): twilio_response = Response() twilio_response.play('http://travellingscholar.com/ammi/message1.mp3') twilio_response.play('http://travellingscholar.com/ammi/message2.mp3') with twilio_response.gather(action='respond', numDigits=1) as g: #g.say('Assalaam walaikum, Ammi Tips par khush amdeed') #g.say(request) g.pause(length=1) return twilio_response
def handle_fourth_response(request): digits = request.POST.get('Digits', '') number = request.POST.get('From', '') twilio_response_four = Response() #twilio_response_four.say(digits) twilio_response_four.play( 'http://travellingscholar.com/ammi/message7a.mp3') twilio_response_four.sms( 'Your newborn will need lots of food to grow. The best food for your newborn is your breastmilk. Feeding her honey or ghee is harmful and a waste of your special milk.', to=number) return twilio_response_four
def handle_recording(): """Play back the caller's recording.""" recording_url = request.values.get("RecordingUrl", None) resp = Response() if recording_url: resp.say("Thanks for howling... take a listen to what you howled.") resp.play(recording_url) resp.say("Goodbye.") else: resp.say("An error has occurred. Goodbye.") return str(resp)
def handle_response(request): digits =request.POST.get('Digits','') twilio_response =Response() 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) return twilio_response
def get(self, request, client_call, pk): call = ClientCall.objects.get(pk=client_call) url = reverse("phone:verify_shelter_availability", kwargs={"pk": pk, "client_call": client_call}) r = Response() r.say("Hello, this is the Continuum, calling on behalf of") r.play(call.client_name) r.say("who is near") r.play(call.location_name) with r.gather(finishOnKey="#", method="POST", action=url, numDigits=1) as g: g.say("Do you %d beds available? Press 1 for yes, and 0 for no." % call.bed_count) return r
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"))
def get(self, request, client_call, pk): call = ClientCall.objects.get(pk=client_call) url = reverse( 'phone:verify_shelter_availability', kwargs={'pk': pk, 'client_call': client_call} ) r = Response() r.say('Hello, this is the Continuum, calling on behalf of') r.play(call.client_name) r.say('who is near') r.play(call.location_name) with r.gather(finishOnKey='#', method='POST', action=url, numDigits=1) as g: g.say('Do you %d beds available? Press 1 for yes, and 0 for no.' % call.bed_count) return r
def play(request, url, loop=None): """See: twilio's website: http://www.twilio.com/docs/api/twiml/play. Usage:: # urls.py urlpatterns = patterns('', # ... url(r'^play/$', 'django_twilio.views.play', { 'url': 'http://blah.com/blah.wav', }), # ... ) """ r = Response() r.play(url, loop=loop) return r
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 hello_monkey(): """Root handler""" people = { '{}'.format(phone_dave): 'David', '{}'.format(phone_kenna): 'Makenna', '{}'.format(phone_brit): 'Britiany', '{}'.format(phone_rob): 'Robert', } name = people.get(request.args.get('From', ''), 'Monkey') resp = Response() resp.say("Hello " + name) resp.play("http://demo.twilio.com/hellomonkey/monkey.mp3") with resp.gather(numDigits=1, action="/hello-monkey/handle-key/", method="POST") as g: g.say('To speak to a real monkey, press 1. ' 'Press 2 to record your own monkey howl. ' 'Press 3 to talk to customer support. ' 'Press any other key to start over.') return str(resp)
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
def twiml(self, tid, play=False): """Generate a TwiML, either to list tracks, or to play one""" ## Get JSON data to generate the TwiML data = open("%s/%s.json" %(sap.twiml_path, tid), 'r').read() json = loads(data) ## Twilio response response = TwilioResponse() ## If we need to play the track, create a TwiML that just <Play> if play: ## Correct digit, play + list when it's done if int(play) <= len(json['tracks']): response.play(json['tracks'][play]['preview']) self.gather(response, json, tid) ## Else, list tracks again else: response.say("Sorry! Wrong digit, please try again.") self.gather(response, json, tid) ## Otherwise, create a TwiML w/ <Gather> to get user input else: response.say("Hello! Here are a few tracks from %s" %(json['artist'])) self.gather(response, json, tid) ## Render Twilio response return str(response)
def twiml(self, tid, play=False): """Generate a TwiML, either to list tracks, or to play one""" ## Get JSON data to generate the TwiML data = open("%s/%s.json" % (sap.twiml_path, tid), 'r').read() json = loads(data) ## Twilio response response = TwilioResponse() ## If we need to play the track, create a TwiML that just <Play> if play: ## Correct digit, play + list when it's done if int(play) <= len(json['tracks']): response.play(json['tracks'][play]['preview']) self.gather(response, json, tid) ## Else, list tracks again else: response.say("Sorry! Wrong digit, please try again.") self.gather(response, json, tid) ## Otherwise, create a TwiML w/ <Gather> to get user input else: response.say("Hello! Here are a few tracks from %s" % (json['artist'])) self.gather(response, json, tid) ## Render Twilio response return str(response)
def handle_response(request): digits = request.POST.get('Digits', '') twilio_response = Response() #twilio_response.play('http://travellingscholar.com/ammi/firstmessage.mp3') if digits == '2': #digits3=request.POST.get('Digits','') twilio_response.play('http://travellingscholar.com/ammi/message3b.mp3') twilio_response.play('http://travellingscholar.com/ammi/message4.mp3') req = 'http://23ee1813.ngrok.com/respond' #r2 = gather_digits(req) twilio_response.gather(action='respond2', numDigits=1) #with twilio_response.gather(action='respond', numDigits=1) as g: #twilio_response.pause(length=1) #second_response= Response() if digits == '1': twilio_response.play('http://travellingscholar.com/ammi/message.mp3') # number = request.POST.get('From', '') # twilio_response.say('A text message is on its way') # twilio_response.sms('You looking lovely today!', to=number) return twilio_response
def ring(request): r = Response() r.play('http://bit.ly/phaltsw') return r
def handle_second_response(request): digits = request.POST.get('Digits', '') twilio_response_two = Response() twilio_response_two.play('http://travellingscholar.com/ammi/message5a.mp3') twilio_response_two.gather(action='respond3', numDigits=1) return twilio_response_two
def ring(request): r = Response() # r.play('http://bit.ly/phaltsw') r.play('https://demo.twilio.com/hellomonkey/monkey.mp3') return r
def handle_second_response(request): digits = request.POST.get('Digits', '') twilio_response_two=Response() twilio_response_two.play('http://travellingscholar.com/ammi/message5a.mp3') twilio_response_two.gather(action='respond3', numDigits=1) return twilio_response_two