<commit_before>#! /usr/bin/env python
# -*- coding: utf-8 -*-

from app import (app, logging)
from flask import (make_response, abort, request)

# globals
from app import r
from app import g
from app import settings
from app import RqlError

from app import AfricasTalkingGateway, AfricasTalkingGatewayException


@app.route('/api/voice/callback/', methods=['POST'])
def voice_callback():
    if request.method == 'POST':
        if request.headers['Content-Type'] != 'application/x-www-form-urlencoded':
            abort(400)

        is_active = request.values.get('isActive')
        session_id = request.values.get('sessionId')
        caller_number = request.values.get('callerNumber')
        print is_active
        print session_id

        if is_active is 1:
            # Compose the response
            response = '<?xml version="1.0" encoding="UTF-8"?>'
            response += '<Response>'
            response += '<GetDigits timeout="20" finishOnKey="#">'
            response += '<Say>How many people are in the room? end with hash sign</Say>'
            response += '</GetDigits>'
            response += '<Say>We did not get your answer. Good bye</Say>'
            response += '</Response>'

            dtmf_digits = request.values.get('dtmfDigits')
            print(dtmf_digits)
            if dtmf_digits == 5:
                api = AfricasTalkingGateway(apiKey_=settings.api_key, username_=settings.username)
                try:
                    api.sendAirtime([caller_number])
                except AfricasTalkingGatewayException:
                    logging.error('Sending airtime failed')

            resp = make_response(response, 200)
            resp.headers['Content-Type'] = "application/xml"
            resp.cache_control.no_cache = True
            return resp

        else:
            duration = request.values.get('durationInSeconds')
            currency_code = request.values.get('currencyCode')
            amount = request.values.get('amount')

            # Compose the response
            response = '<?xml version="1.0" encoding="UTF-8"?>'
            response += '<Response>'
            response += '<GetDigits timeout="20" finishOnKey="#">'
            response += '<Say>How many people are in the room? end with hash sign</Say>'
            response += '</GetDigits>'
            response += '<Say>We did not get your answer. Good bye</Say>'
            response += '</Response>'

            try:
                r.table('User').get(caller_number).update({'duration': duration, 'currencyCode': currency_code,
                                                           'sessionId': session_id, 'amount': amount}).run(g.rdb_conn)
            except RqlError:
                logging.error('Save user call info failed on voice callback')

            resp = make_response(response, 200)
            resp.headers['Content-Type'] = "application/xml"
            resp.cache_control.no_cache = True
            return resp

    else:
        resp = make_response('Bad Request', 400)
        resp.headers['Content-Type'] = "application/xml"
        resp.cache_control.no_cache = True
        return resp<commit_msg>voice callback url update<commit_after>#! /usr/bin/env python
# -*- coding: utf-8 -*-

from app import (app, logging)
from flask import (make_response, abort, request)

# globals
from app import r
from app import g
from app import settings
from app import RqlError

from app import AfricasTalkingGateway, AfricasTalkingGatewayException


@app.route('/api/voice/callback/', methods=['POST'])
def voice_callback():
    if request.method == 'POST':
        if request.headers['Content-Type'] != 'application/x-www-form-urlencoded':
            abort(400)

        is_active = request.values.get('isActive')
        session_id = request.values.get('sessionId')
        caller_number = request.values.get('callerNumber')
        print is_active
        print session_id

        if is_active == 0:
            # Compose the response
            response = '<?xml version="1.0" encoding="UTF-8"?>'
            response += '<Response>'
            response += '<GetDigits timeout="20" finishOnKey="#">'
            response += '<Say playBeep="false" >How many people are in the room? end with hash sign</Say>'
            response += '</GetDigits>'
            response += '<Say>We did not get your answer. Good bye</Say>'
            response += '</Response>'

            resp = make_response(response, 200)
            resp.headers['Content-Type'] = "application/xml"
            resp.cache_control.no_cache = True
            return resp

        elif is_active == 1:
            # Compose the response
            response = '<?xml version="1.0" encoding="UTF-8"?>'
            response += '<Response>'
            response += '<GetDigits timeout="20" finishOnKey="#">'
            response += '<Say>We\'ll see</Say>'
            response += '</GetDigits>'
            response += '<Say>We did not get your answer. Good bye</Say>'
            response += '</Response>'

            dtmf_digits = request.values.get('dtmfDigits')
            print(dtmf_digits)
            if dtmf_digits == 5:
                api = AfricasTalkingGateway(apiKey_=settings.api_key, username_=settings.username)
                try:
                    api.sendAirtime([caller_number])
                except AfricasTalkingGatewayException:
                    logging.error('Sending airtime failed')

            resp = make_response(response, 200)
            resp.headers['Content-Type'] = "application/xml"
            resp.cache_control.no_cache = True
            return resp

        else:
            duration = request.values.get('durationInSeconds')
            currency_code = request.values.get('currencyCode')
            amount = request.values.get('amount')

            # Compose the response
            response = '<?xml version="1.0" encoding="UTF-8"?>'
            response += '<Response>'
            response += '<GetDigits timeout="20" finishOnKey="#">'
            response += '<Say playBeep="false" >How many people are in the room? end with hash sign</Say>'
            response += '</GetDigits>'
            response += '<Say>We did not get your answer. Good bye</Say>'
            response += '</Response>'

            try:
                r.table('User').get(caller_number).update({'duration': duration, 'currencyCode': currency_code,
                                                           'sessionId': session_id, 'amount': amount}).run(g.rdb_conn)
            except RqlError:
                logging.error('Save user call info failed on voice callback')

            resp = make_response(response, 200)
            resp.headers['Content-Type'] = "application/xml"
            resp.cache_control.no_cache = True
            return resp

    else:
        resp = make_response('Bad Request', 400)
        resp.headers['Content-Type'] = "application/xml"
        resp.cache_control.no_cache = True
        return resp
{'fraction_non_alphanumeric': 0.12119479777047305, 'fraction_numerical': 0.008432185222238101, 'mean_word_length': 2.099202834366696, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 5, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6368916', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1803, 'n_words': 466}