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