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)
Beispiel #2
0
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()
Beispiel #3
0
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()
Beispiel #4
0
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)
Beispiel #6
0
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 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 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 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)