def connect_dgf(): response = VoiceResponse() farward_to = ccConfig['settings']['GDF_connection'] # print(farward_to) response.dial(farward_to, action=url_for('quit_call')) # print(farward_to) return str(response)
def sipfailover(request): print(request) dialSipResponseCode = "" dialCallStatus = "" response = VoiceResponse() dial = Dial() if request.method == 'GET': ReqDict = request.GET elif request.method == 'POST': ReqDict = request.POST print(ReqDict) for i, v in ReqDict.items(): print('current item is ' + i + ' and value is ' + v) if i == "DialSipResponseCode": dialSipResponseCode = v if i == "DialCallStatus": dialCallStatus = v if (int(dialSipResponseCode) > 299 or dialCallStatus == "failed"): dial.sip( 'sip:[email protected];transport=tls' ) response.append(dial) return HttpResponse(response, content_type='text/xml')
def test_returns_laml(self): from signalwire.voice_response import VoiceResponse, Dial r = VoiceResponse() r.say("Welcome to SignalWire!") self.assertEqual( str(r), '<?xml version="1.0" encoding="UTF-8"?><Response><Say>Welcome to SignalWire!</Say></Response>' )
def perform_action(): response = VoiceResponse() gather = Gather(input='speech dtmf', timeout=5, num_digits=1, action='/perform') gather.say( 'Say balance or press 1 for your balance,say credit or press 2 for your credit card due date' ) response.append(gather) return response.to_xml()
def lookup_session(): # Initialize SignalWire Client client = signalwire_client( os.environ['SIGNALWIRE_PROJECT'], os.environ['SIGNALWIRE_TOKEN'], signalwire_space_url=os.environ['SIGNALWIRE_SPACE']) # Read proxy number from request proxy_number = request.values.get("To") # Read participant number from request leg_1 = request.values.get("From") # read proxy sessions from json file with open('proxy_sessions.json') as f: sessions = json.load(f) # Lookup session, find session that has proxy number and participant that matches for session in sessions: # Lookup the second session participant, if A is calling if session["Proxy_Number"] == proxy_number and session[ "Participant_A_Number"] == leg_1: leg_2 = session["Participant_B_Number"] found = True break # Lookup the second session participant, if B is calling elif session["Proxy_Number"] == proxy_number and session[ "Participant_B_Number"] == leg_1: leg_2 = session["Participant_A_Number"] found = True break # We did not find anything yet found = False if found == True: # Check if a CallSid exists, if it does, it is a voice call if "CallSid" in request.values.keys(): # Bridge legs voice response = VoiceResponse() response.dial(leg_2, callerId=proxy_number) return str(response) # Check if a MessageSid exists, if it does it is a text message elif "MessageSid" in request.values.keys(): # Send a message, with challenge code to phone number provided. message = client.messages.create(from_=proxy_number, body=request.values.get("Body"), to=leg_2) return "200" else: # No session found response = VoiceResponse() response.say( "We are sorry but your call can not be completed at this time. Good Bye!" ) return str(response)
def call_2fa(): # Read in passed digits from request auth_code = request.values.get('auth_code') # Prepare a voice response response = VoiceResponse() # Voice responses, TTS message response.say('Your authorization code is: ' + auth_code) response.say('Repeating...') response.say('Your authorization code is: ' + auth_code) response.say('Thank you for calling, GoodBye!') # return voice response LaML return str(response)
def perform_action(): response = VoiceResponse() speech = request.form.get('SpeechResult') digits = request.form.get('Digits') replace = '' if (speech == 'balance' or digits == '1'): response.say('Your balance is: PLACEHOLDER') replace = '<say-as interpret-as="currency">' + get_balance( ) + '</say-as>' if (speech == 'credit' or digits == '2'): response.say('Your credit card is due: PLACEHOLDER') replace = '<say-as interpret-as="date" format="mdy">' + get_credit_card_due_date( ) + '</say-as>' else: response.redirect('/ask') return response.to_xml().replace('PLACEHOLDER', replace)
def get_menu(): response = VoiceResponse() # read menus from config menus = ccConfig['settings']['menus'] # check to see if a default menu was specified, else default to "main" menu = request.values.get("menu") if menu not in menus: menu = "main" # read input_type variable input_type = request.values.get("input_type") # check if user input was provided via dtmf entry if input_type == "dtmf": # get digits pressed at menu digits = request.values.get("Digits") input_action = menus[menu][digits]["action"] response.redirect(url=input_action) response.hangup() else: # no user input was detected, so lets present a menu gather = Gather(action='/get_menu' + "?menu=" + menu, input='dtmf', timeout="5", method='POST', numDigits="1") # loop through menus and generate menu options for key in menus[menu]: print(key, '->', menus[menu][key]["verbiage"]) gather.say(menus[menu][key]["verbiage"], voice=ccConfig['settings']['textToSpeech']['voice']) # add menu to response response.append(gather) response.hangup() # return response return str(response)
def dial_conference(conferenceName, muted=False, beep=True, startConferenceOnEnter=True, endConferenceOnExit=False, statusCallbackEvent="start end join leave speaker", statusCallback=HOSTNAME + "/conference_event", statusCallbackMethod="POST"): response = VoiceResponse() response.say("Dialing " + conferenceName + " one moment please...", voice=ccConfig['settings']['textToSpeech']['voice']) dial = Dial() dial.conference(conferenceName, muted=muted, beep=beep, startConferenceOnEnter=startConferenceOnEnter, endConferenceOnExit=endConferenceOnExit, statusCallbackEvent=statusCallbackEvent, statusCallback=statusCallback, statusCallbackMethod=statusCallbackMethod) response.append(dial) print(response) # return response return response
def transfer_call(): response = VoiceResponse() farward_to = ccConfig['settings']['callTransferTo_'] # print(farward_to) response.say("please wait your call is connecting....") response.dial(farward_to, action=url_for('quit_call')) print(farward_to) return str(response)
def post_conference(): response = VoiceResponse() # Check if announcment should be played if ccConfig['settings']['enableExitSurvey']: response.say(ccConfig['settings']['messages']['surveyEntryMessage'], voice=ccConfig['settings']['textToSpeech']['voice']) response.redirect(HOSTNAME + "/get_survey", Method="POST") # Check if announcment should be played if ccConfig['settings']['enableExitMessage']: response.say(ccConfig['settings']['messages']['exitMessage'], voice=ccConfig['settings']['textToSpeech']['voice']) return str(response)
def dial_sip(request): print(request) dialSipResponseCode = "" dialCallStatus = "" response = VoiceResponse() if request.method == 'GET': ReqDict = request.GET elif request.method == 'POST': ReqDict = request.POST URL = 'http://' + DOMAIN_NAME + ':' + PYTHON_PORT + '/sipfailover' dial = Dial(action=URL) for i, v in ReqDict.items(): print('current item is ' + i + ' and value is ' + v) # # Call routing happens here # # if you want to parse customer numbers #if i == "From" and v == CELL_PHONE: # print("your customer called in... sending to first sip endpoint"); # dial.sip(SIP_DIAL); # if you want to parse dialed numbers if i == "To" and v == SW_NUMBER_1: print( "random somebody dialed your SW number, sending to second sip endpoint" ) dial.sip(SIP_DIAL) elif i == "To" and v == SW_NUMBER_2: print("your customer called in... sending to first sip endpoint") dial.sip(SIP_FAILOVER) response.append(dial) return HttpResponse(response, content_type='text/xml')
def check_number(): response = VoiceResponse() from_number = request.form.get('From') if from_number not in get_blocklist(): response.redirect( os.environ.get( 'REDIRECT_PATH', 'https://example.signalwire.com/laml-bins/55ab7685-e9c3-4449-b1f0-07ff083d041e' )) else: response.hangup() return response.to_xml()
def start_voice(): response = VoiceResponse() speech = request.form.get('SpeechResult') digits = request.form.get('Digits') print(speech) print(digits) if (speech == '1234' or digits == '1234'): response.redirect('/ask') else: gather = Gather(input='speech dtmf', timeout=5, num_digits=4) gather.say('Please say or enter your PIN') response.append(gather) return response.to_xml()
def voice_entry(): response = VoiceResponse() response.say( "Please leave a message at the beep. Press the pound key when finished." ) response.record(finishOnKey="#", maxLength="1", action="/hangup", transcribe="true", transcribeCallback="/transcribe_webhook", recordingStatusCallback="/recording_webhook") # return response return str(response)
def inbound_voice(): response = VoiceResponse() # Check if call should be recorded if ccConfig['settings']['enableRecording']: enableRecording(str(request.values.get('CallSid'))) response.say(ccConfig['settings']['messages']['entryMessage'], voice=ccConfig['settings']['textToSpeech']['voice']) # Check if announcment should be played if ccConfig['settings']['enableAnnouncment']: response.say(ccConfig['settings']['messages']['announcmentMessage'], voice=ccConfig['settings']['textToSpeech']['voice']) # Redirect to the main menu set in config.json response.redirect(HOSTNAME + "/get_menu?menu=" + ccConfig['settings']['mainMenu'], method="POST") # return response return str(response)
def enqueue(queueName, action=HOSTNAME + "/enqueue_event", method="POST", waitUrl=HOSTNAME + "/wait_music_queue", waitUrlMethod="POST"): response = VoiceResponse() response.say("Dialing " + queueName + " one moment please...", voice=ccConfig['settings']['textToSpeech']['voice']) response.enqueue(queueName, action=action, method=method, waitUrl=waitUrl, waitUrlMethod=waitUrlMethod) print(response) # return response return response
def dial_verify(): # Initialize VoiceResponse response = VoiceResponse() if "SpeechResult" in request.values: if request.values.get("SpeechResult") == "Yes.": # Read the passed in number to dial from the request number_to_dial = request.values.get("number_to_dial") # Append the gather response.dial(number_to_dial) return str(response) response.say("OK. Thank you for calling goodbye!") return str(response)
def dial_sip(request): dialSipResponseCode = "" dialCallStatus = "" response = VoiceResponse() dial = Dial() if request.method == 'GET': ReqDict = request.GET elif request.method == 'POST': ReqDict = request.POST print(ReqDict) for i, v in ReqDict.items(): if i == "DialSipResponseCode": dialSipResponseCode = v if i == "DialCallStatus": dialCallStatus = v if (int(dialSipResponseCode) > 299 or dialCallStatus == "failed"): dial.sip('sip:[email protected]') response.append(dial) else: dial.sip('sip:[email protected]') response.append(dial) return HttpResponse(response, content_type='text/xml')
from signalwire.voice_response import VoiceResponse r = VoiceResponse() r.say("Welcome to SignalWire!") print(str(r))
def get_voicemail(): response = VoiceResponse() response.say('You have reached our voicemail, please leave a message.') response.hangup() return str(response)
def get_voicemail(): response = VoiceResponse() response.say('You have reached our voicemail, please leave a message.', voice=ccConfig['settings']['textToSpeech']['voice']) response.hangup() return str(response)
def get_survey(): response = VoiceResponse() response.say('This is a survey placeholder...', voice=ccConfig['settings']['textToSpeech']['voice']) return str(response)
def dial_prompt(): # Initialize VoiceResponse response = VoiceResponse() # check if user input was provided via dtmf entry if "SpeechResult" in request.values: # Read speech result speech_result = request.values.get("SpeechResult") # Validate Number Provided number = re.sub("[^0-9]", "", speech_result) # Make E164 if len(number) == 11: number = "+" + number # Assume US Number, Make E164 elif len(number) == 10: number = "+1" + number # We did not determine a valide phone number else: response.say( "I am sorry, I did not understand you. Please try again.", voice="man") response.redirect("/dial-prompt") return str(response) # Prompt user gather = Gather(action='/dial-verify?number_to_dial=' + number, input='speech', speechTimeout="auto", timeout="10", method='GET') # Append say to gather to produce TTS gather.say("We detectected " + speech_result + " Would you like me to connect you? ") # Append the gather response.append(gather) # Hangup the call response.hangup() else: # Prompt user gather = Gather(action='/dial-prompt', input='speech', speechTimeout="auto", timeout="10", method='GET') # Append say to gather to produce TTS gather.say("What number would you like to dial?") # Append the gather response.append(gather) # Hangup the call response.hangup() # return response return str(response)
def wait_music_queue(): count = 0 if request.values.get('count'): count = int(request.values.get('count')) + 1 response = VoiceResponse() # Update the queueStats Logs updateLogs('queueStats', request.values) # Load the queueStatsMessage from config queueStatsMessage = ccConfig['settings']['messages']['queueStatsMessage'] # Replace Template Vars With Values queueStatsMessage = queueStatsMessage.replace( "%QueuePosition%", str(request.values.get("QueuePosition"))) queueStatsMessage = queueStatsMessage.replace( "%CurrentQueueSize%", str(request.values.get("CurrentQueueSize"))) queueStatsMessage = queueStatsMessage.replace( "%AvgQueueTime%", str(request.values.get("AvgQueueTime"))) # If enabled play queueStats to caller on hold response.say(queueStatsMessage, voice=ccConfig['settings']['textToSpeech']['voice']) if ccConfig['settings']['enableWaitingAds']: if count < len(ccConfig['settings']['waitingAds']): response.play(ccConfig['settings']['waitingAds'][count]) else: count = 0 response.play(ccConfig['settings']['waitingAds'][count]) if ccConfig['settings']['enableWaitingMusic']: for music in ccConfig['settings']['waitingMusics']: response.play(music) response.redirect(HOSTNAME + "/wait_music_queue?count=" + str(count), method="POST") return str(response)
def hangup(): response = VoiceResponse() response.say('Thank you! Good Bye!') response.hangup() return str(response)
def get_menu(): response = VoiceResponse() # read menus from json file with open('menus.json') as f: menus = json.load(f) # check to see if a default menu was specified, else default to "main" menu = request.values.get("menu") if menu not in menus: menu = "main" # read input_type variable input_type = request.values.get("input_type") # check if user input was provided via dtmf entry if input_type == "dtmf": # get digits pressed at menu digits = request.values.get("Digits") input_action = menus[menu][digits]["action"] response.say("you pressed " + digits) response.redirect(url=input_action) response.hangup() else: # no user input was detected, so lets present a menu gather = Gather(action='/get_menu' + "?menu=" + menu, input='dtmf', timeout="3", method='GET') # loop through menus and generate menu options for key in menus[menu]: print(key, '->', menus[menu][key]["verbiage"]) gather.say(menus[menu][key]["verbiage"]) # add menu to response response.append(gather) response.hangup() # return response return str(response)
def quit_call(): response = VoiceResponse() response.say('Thank you for calling Eagle.net') response.hangup() return str(response)