Ejemplo n.º 1
0
def ivr():
    response = plivoxml.Response()
    if request.method == 'GET':
        # Go to http://plivo.com/docs/xml/getdigits/ for more details on GetDigits xml
        getdigits_action_url = url_for('ivr', _external=True)
        getDigits = plivoxml.GetDigits(action=getdigits_action_url,
                                       method='POST',
                                       timeout=7,
                                       numDigits=1,
                                       retries=1)
        getDigits.addSpeak(IVR_MESSAGE)
        response.add(getDigits)
        response.addSpeak(NO_INPUT_MESSAGE)

        return Response(str(response), mimetype='text/xml')
    elif request.method == 'POST':
        digit = request.form.get('Digits')

        if digit == "1":
            # Fetch a random joke using the Reddit API.
            joke = joke_from_reddit()
            response.addSpeak(joke)
        elif digit == "2":
            # Listen to a song
            response.addPlay(PLIVO_SONG)
        else:
            response.addSpeak(WRONG_INPUT_MESSAGE)

        return Response(str(response), mimetype='text/xml')
Ejemplo n.º 2
0
def call_guide(request, format=None):#Direction=inbound&From=13172097889&CallerName=%2B13172097889&BillRate=0.0085&To=13174275522&CallUUID=2e9856d8-135e-11e7-b774-dbf71cdc2903&CallStatus=ringing&Event=StartApp
	if request.method=="POST" and validate_signature(request, auth_token):
		intro = "Thank you for using Saga! Please enter the five digit code of the guide you wish to speak with."
		NO_INPUT_MESSAGE = "Sorry, I didn't catch that. Please hangup and try again later."
		r = plivoxml.Response()
		r.addSpeak(intro)
		getDigits = plivoxml.GetDigits(action=root + reverse('telecom:connect-guide'), method='POST', timeout=7, numDigits=5, retries=1)
		r.add(getDigits)
		r.addSpeak(NO_INPUT_MESSAGE)
		print r.to_xml()
		return HttpResponse(str(r),content_type="text/xml")
Ejemplo n.º 3
0
def ivr():
    response = plivoxml.Response()
    if request.method == 'GET':
        # GetDigit XML Docs - http://plivo.com/docs/xml/getdigits/
        getdigits_action_url = url_for('ivr', _external=True)
        getDigits = plivoxml.GetDigits(action=getdigits_action_url,
                                       method='POST',
                                       timeout=7,
                                       numDigits=1,
                                       retries=1)

        getDigits.addSpeak(IVR_MESSAGE1)
        response.add(getDigits)
        response.addSpeak(NO_INPUT_MESSAGE)
        print response.to_xml()
        return Response(str(response), mimetype='text/xml')

    elif request.method == 'POST':
        digit = request.form.get('Digits')
        print digit
        if digit == "1":
            # Read out a text.
            getdigits_action_url1 = url_for('tree', _external=True)
            getDigits1 = plivoxml.GetDigits(action=getdigits_action_url1,
                                            method='POST',
                                            timeout=7,
                                            numDigits=1,
                                            retries=1)
            getDigits1.addSpeak(IVR_MESSAGE2)
            response.add(getDigits1)
            response.addSpeak(NO_INPUT_MESSAGE)

        elif digit == "2":
            # Listen to a song
            response.addPlay(PLIVO_SONG)

        else:
            response.addSpeak(WRONG_INPUT_MESSAGE)

        print response.to_xml()
        return Response(str(response), mimetype='text/xml')
Ejemplo n.º 4
0
def ivr_start():
    r = plivoxml.Response()
    getdigits_action_url = url_for('ivr_next', _external=True)
    get_digits = plivoxml.GetDigits(action=getdigits_action_url,
                                    method='GET',
                                    timeout=7,
                                    numDigits=1,
                                    retries=2,
                                    redirect='true')

    get_digits.addSpeak(
        "Welcome to Plivo Training IVR. Press a digit to continue")
    r.add(get_digits)
    r.addSpeak("You haven't pressed any valid key")
    print(r.to_xml())
    return Response(str(r), mimetype='text/xml')
Ejemplo n.º 5
0
def transfer():
    r = plivoxml.Response()
    getdigits_action_url = url_for('transfer_action', _external=True)
    get_digits = plivoxml.GetDigits(action=getdigits_action_url,
                                    method='GET',
                                    timeout=7,
                                    numDigits=1,
                                    retries=1,
                                    redirect='false')
    get_digits.addSpeak("Press 1 to transfer this call")
    r.add(get_digits)
    params = {
        'length': "10"  # Time to wait in seconds
    }
    r.addWait(**params)
    print(r.to_xml())
    return Response(str(r), mimetype='text/xml')
Ejemplo n.º 6
0
def connect():
    r = plivoxml.Response()
    if request.method == 'GET':
        # Generate a Dial XML with the details of the number to call
        body = "https://s3.ap-south-1.amazonaws.com/smsresource/Bankruptcy.mp3"
        prompt = "Press 1 to connect to another caller"
        no_input = "No input received. Goodbye"
        getdigits_action_url = url_for('connect', _external=True)
        getDigits = plivoxml.GetDigits(action=getdigits_action_url,
                                       method='POST',
                                       timeout=15,
                                       numDigits=1,
                                       retries=1)
        r.addPlay(body)
        r.add(getDigits)
        r.addSpeak(no_input)

        return Response(str(r), mimetype='text/xml')

    elif request.method == 'POST':
        confirmation = "Connecting your call.."

        digit = request.form.get('Digits')

        if digit == "1":
            r.addSpeak(confirmation)
            number = "13346410046"
            callerId = request.values.get('To')
            print('Caller ID is ' + str(callerId))
            callerName = request.values.get('To')
            print('Caller name is ' + str(callerName))
            params = {
                #'callerId': '{}'.format(callerId),
                'callerId': '443-362-9016',
                #'callerName': '{}'.format(callerName)
                'callerName': '443-362-9016'
            }
            d = r.addDial(**params)
            d.addNumber(number)
        else:
            r.addSpeak("Invalid Digit")

        print r.to_xml()
        return Response(str(r), mimetype='text/xml')
Ejemplo n.º 7
0
def index():
    response = plivo.Response()
    response.addSpeak(body="Hello, welcome to Plivo's " "guessing game app!")
    response.addWait(length=2)

    absolute_action_url = url_for('mm_response', _external=True)
    getDigits = plivo.GetDigits(action=absolute_action_url,
                                method='POST',
                                timeout=4,
                                numDigits=4,
                                retries=1)
    getDigits.addSpeak(body='To play the game Press 1')
    getDigits.addWait(length=1)
    getDigits.addSpeak(body='To learn how to play Press 2')
    getDigits.addWait(length=1)
    getDigits.addSpeak(body='You can end this call at any time.')

    response.add(getDigits)

    return Response(str(response), mimetype='text/xml')
Ejemplo n.º 8
0
def get_digits():
    args = request.args

    digits = args.get('Digits', None)
    from_number = args.get('From', None)
    to_number = args.get('To', None)
    wrong_input = args.get('wrong_input', False)

    response = plivo.Response()

    confirm_key = '1'
    timeout = DIAL_TIMEOUT

    callback_url = url_for('dial_callback', _external=True)
    dial_action_url = url_for('dial_action', _external=True)
    record_dial_action_url = url_for('record_dial_action', _external=True)
    dial_music_url = url_for('dial_music', _external=True)
    confirm_sound_url = url_for('confirm_sound_speak', _external=True)

    rd = get_redis_connection()
    on_call = rd.get('on_call_%s' % FIRST_CONTACT)

    # Sales
    if digits == '1':
        if on_call:
            contact = BROADCAST_CONTACTS[0]
        else:
            contact = FIRST_CONTACT

        record = response.addRecord(action=record_dial_action_url,
                                    startOnDialAnswer="true",
                                    redirect="false",
                                    maxLength="3600")
        dial = response.addDial(action=dial_action_url,
                                method='GET',
                                dialMusic=dial_music_url,
                                callerName=to_number,
                                callerId=to_number,
                                timeout=timeout,
                                confirmKey=confirm_key,
                                confirmSound=confirm_sound_url,
                                callbackUrl=callback_url,
                                callbackMethod='GET')
        dial = add_endpoint_to_dial(dial, contact)

        hipchat_body = 'Forwarding sales call to %s.' % contact
        q.enqueue(send_hipchat,
                  VOICEMAIL_HIPCHAT_ROOMS,
                  hipchat_body,
                  color='purple')
    elif not wrong_input:
        action_url = url_for('get_digits', _external=True)
        action_url = action_url + '?wrong_input=True&'
        getDigits = plivo.GetDigits(action=action_url,
                                    method='GET',
                                    timeout=5,
                                    numDigits=1,
                                    retries=1)
        getDigits.addSpeak(WRONG_INPUT_MESSAGE)
        response.add(getDigits)

        response.addSpeak(GOODBYE_MESSAGE)
    elif wrong_input:
        response.addSpeak(WRONG_INPUT_GOODBYE)
    else:
        response.addSpeak(GOODBYE_MESSAGE)

    return Response(str(response), mimetype='text/xml')
Ejemplo n.º 9
0
def forward():
    args = request.args

    from_number = args.get('From', '')
    to_number = args.get('To', '')
    call_status = args.get('CallStatus', '')
    call_uuid = args.get('CallUUID', '')
    source = args.get('source', '')

    rd = get_redis_connection()
    rd.set(to_number, source)

    response = plivo.Response()

    getdigits_action_url = url_for('get_digits', _external=True)
    getDigits = plivo.GetDigits(action=getdigits_action_url,
                                method='GET',
                                timeout=IVR_TIMEOUT,
                                numDigits=1,
                                retries=1)
    getDigits.addSpeak(IVR_MESSAGE)
    response.add(getDigits)

    getDigits = plivo.GetDigits(action=getdigits_action_url,
                                method='GET',
                                timeout=IVR_TIMEOUT,
                                numDigits=1,
                                retries=1)
    getDigits.addSpeak(NO_INPUT_MESSAGE)
    response.add(getDigits)

    response.addSpeak(GOODBYE_MESSAGE)

    if call_status == "ringing":
        q.enqueue(send_hipchat,
                  VOICEMAIL_HIPCHAT_ROOMS,
                  LINE_SEPARATOR,
                  color='gray')
        q.enqueue(incoming_call_details, to_number, from_number, source)

    elif call_status == "completed":
        email_body = rd.get('call_recording_email_body' + call_uuid)
        sms_body = rd.get('call_recording_sms_body' + call_uuid)
        hipchat_body = rd.get('call_recording_hipchat_body' + call_uuid)

        rd.delete('call_recording_email_body' + call_uuid)
        rd.delete('call_recording_sms_body' + call_uuid)
        rd.delete('call_recording_hipchat_body' + call_uuid)

        if email_body:
            q.enqueue(send_email, CALL_RECORDING_EMAIL_RECEIVERS,
                      CALL_RECORDING_EMAIL_SUBJECT, email_body)
            q.enqueue(send_sms, CALL_RECORDING_SMS_RECEIVERS, sms_body)
            q.enqueue(send_hipchat,
                      CALL_RECORDING_HIPCHAT_ROOMS,
                      hipchat_body,
                      color='gray')
        q.enqueue(send_hipchat,
                  VOICEMAIL_HIPCHAT_ROOMS,
                  LINE_SEPARATOR,
                  color='gray')

    return Response(str(response), mimetype='text/xml')
Ejemplo n.º 10
0
def play_game():
    if not request.args.get('guesses', None):
        secret = random.randint(1, 100)
        guesses = 10

        response = plivo.Response()
        absolute_action_url = url_for('play_game',
                                      _external=True,
                                      **{
                                          'secret': str(secret),
                                          'guesses': str(guesses)
                                      })
        getDigits = plivo.GetDigits(action=absolute_action_url,
                                    method='POST',
                                    timeout=10,
                                    numDigits=4,
                                    retries=1)
        getDigits.addSpeak(body="I have thought of a secret number between "
                           "one and one hundred. "
                           "You have ten guesses to find it!")
        getDigits.addSpeak(body="You can make your guess now.")
        response.add(getDigits)
        return Response(str(response), mimetype='text/xml')
    else:
        secret = int(request.args.get('secret', '0'))
        guesses = int(request.args.get('guesses', '0')) - 1
        absolute_action_url = url_for('play_game',
                                      _external=True,
                                      **{
                                          'secret': str(secret),
                                          'guesses': str(guesses)
                                      })

        input_num = request.form.get('Digits', "0")
        response = plivo.Response()
        try:
            input_num = int(input_num)
        except ValueError, e:
            print e
            return exit_sequence()

        if input_num == secret:
            response.addSpeak("Congratulations! %d is the right number!"
                              " You have guessed"
                              " it in %d guesses - your score is %d." %
                              (secret, 10 - guesses, guesses + 1))
            response.addWait(length=2)
            response.addHangup()
            return Response(str(response), mimetype='text/xml')
        else:
            if input_num > secret:
                answer = "Sorry, you guessed %d. The secret is lesser."
            else:
                answer = "Sorry, you guessed %d. The secret is greater."
            response.addSpeak(answer % (input_num))
            if guesses > 0:
                getDigits = plivo.GetDigits(action=absolute_action_url,
                                            method='POST',
                                            timeout=10,
                                            numDigits=4,
                                            retries=1)
                getDigits.addWait(length=1)
                getDigits.addSpeak(
                    "You have %d guesses remaining! Guess again!" % guesses)
                response.add(getDigits)
            else:
                response.addWait(length=1)
                response.addSpeak(
                    "Sorry, you don't have any remaining guesses. The secret was %d."
                    % (secret))
                response.addHangup()
            return Response(str(response), mimetype='text/xml')