コード例 #1
0
ファイル: hotline_routes.py プロジェクト: HelperLine/backend
def route_hotline_forward2(api_version, language, call_id, helper_id):

    resp = VoiceResponse()

    if language not in ["de", "en-gb"]:
        resp.redirect('/v1/hotline/error/language')
        return str(resp)

    if api_version == "v1":
        forward_call_result = routing.get_params_dict(request)
        dial_call_status = forward_call_result["DialCallStatus"]

        if dial_call_status == "completed":
            resp.say(hotline_translation['after_forward_successful'][language],
                     voice='woman',
                     language=language)
        else:
            forwarding.flag_helper(call_id, helper_id, dial_call_status)
            call_scripts.reject_call(call_id, helper_id)
            resp.say(
                hotline_translation['after_forward_not_successful'][language],
                voice='woman',
                language=language)

    else:
        resp.redirect('/v1/hotline/error/api_version')

    return str(resp)
コード例 #2
0
def route_verification_phone_code(api_version, language):

    resp = VoiceResponse()

    if api_version == "v1":
        if language in ["de", "en-gb"]:
            if 'Digits' in request.values:
                token = request.values['Digits']
                finished_on_key = request.values['FinishedOnKey']

                if len(token) == 5 and finished_on_key == '#':
                    phone_number = routing.get_params_dict(request)['Caller']
                    verification_result = phone_verification.verify(token, phone_number)

                    if verification_result['status'] == 'ok':
                        resp.say(hotline_translation['verification_success'][language], voice='woman', language=language)
                        return str(resp)
                    else:
                        resp.say(hotline_translation['verification_fail'][language], voice='woman', language=language)


            gather = Gather(num_digits=6, finish_on_key='#')
            gather.say(hotline_translation['verification_enter_code'][language], voice='woman', language=language)
            resp.append(gather)

            resp.redirect(f'/backend/{api_version}/{language}/phone/code')
        else:
            resp.redirect('/v1/hotline/error/language')
    else:
        # Programming Error
        resp.redirect('/v1/hotline/error/api_version')

    return str(resp)
コード例 #3
0
def route_authentication_logout(api_version, account_type):

    if api_version == "v1":

        params_dict = routing.get_params_dict(request)

        if account_type == "helper":
            authentication_result = tokening.check_helper_api_key(params_dict)
            if authentication_result["status"] != "ok":
                return formatting.postprocess_response(authentication_result)

            # Route will always return {"status": "ok"}
            return helper_logout(params_dict['email'],
                                 params_dict['api_key']), 200

        elif account_type == "admin":
            authentication_result = tokening.check_admin_api_key(params_dict)
            if tokening.check_admin_api_key(params_dict)["status"] != "ok":
                return formatting.postprocess_response(authentication_result)

            # Route will always return {"status": "ok"}
            return admin_logout(params_dict['email'],
                                params_dict['api_key']), 200

        else:
            return formatting.status("account_type invalid"), 400
    else:
        # Programming Error
        return formatting.status("api_version invalid"), 400
コード例 #4
0
ファイル: rest_account.py プロジェクト: HelperLine/backend
    def post(self):
        # Create a new account
        params_dict = routing.get_params_dict(request, print_out=True)

        validation_result = validating.validate_create_account(params_dict)
        if validation_result["status"] != "ok":
            return formatting.postprocess_response(validation_result)

        result_dict = account_scripts.create_account(params_dict)
        return formatting.postprocess_response(result_dict)
コード例 #5
0
ファイル: rest_filter.py プロジェクト: HelperLine/backend
    def get(self):
        params_dict = routing.get_params_dict(request, print_out=True)

        authentication_result = tokening.check_helper_api_key(
            params_dict,
            new_api_key=(os.getenv("ENVIRONMENT") == "production"))
        if authentication_result["status"] != "ok":
            return formatting.postprocess_response(authentication_result)

        result_dict = filter_scripts.get_filter(params_dict['email'])
        return formatting.postprocess_response(
            result_dict, new_api_key=authentication_result["api_key"])
コード例 #6
0
ファイル: rest_filter.py プロジェクト: HelperLine/backend
    def put(self):
        params_dict = routing.get_params_dict(request, print_out=True)

        authentication_result = tokening.check_helper_api_key(params_dict)
        if authentication_result["status"] != "ok":
            return formatting.postprocess_response(authentication_result)

        validation_result = validating.validate_edit_filter(params_dict)
        if validation_result["status"] != "ok":
            return formatting.postprocess_response(validation_result)

        result_dict = filter_scripts.modify_filter(params_dict)
        return formatting.postprocess_response(result_dict)
コード例 #7
0
ファイル: rest_account.py プロジェクト: HelperLine/backend
    def get(self):
        # Get all infos for a specific account
        params_dict = routing.get_params_dict(request)

        authentication_result = tokening.check_helper_api_key(
            params_dict,
            new_api_key=(os.getenv("ENVIRONMENT") == "production"))
        if authentication_result["status"] != "ok":
            return formatting.postprocess_response(authentication_result)

        result_dict = account_scripts.get_account(params_dict['email'])
        return formatting.postprocess_response(
            result_dict, new_api_key=authentication_result["api_key"])
コード例 #8
0
ファイル: rest_account.py プロジェクト: HelperLine/backend
    def put(self):
        # Modify an existing account
        params_dict = routing.get_params_dict(request)

        authentication_result = tokening.check_helper_api_key(params_dict)
        if authentication_result["status"] != "ok":
            return formatting.postprocess_response(authentication_result)

        validation_result = validating.validate_edit_account(params_dict)
        if validation_result["status"] != "ok":
            return formatting.postprocess_response(validation_result)

        result_dict = account_scripts.modify_account(params_dict)
        return formatting.postprocess_response(result_dict)
コード例 #9
0
def route_helper_phone_trigger(api_version):

    if api_version == "v1":
        params_dict = routing.get_params_dict(request)

        authentication_result = tokening.check_helper_api_key(params_dict)
        if authentication_result["status"] != "ok":
            return formatting.postprocess_response(authentication_result)

        result_dict = phone_verification.trigger(params_dict['email'])
        return formatting.postprocess_response(result_dict)

    else:
        # Programming Error
        return formatting.status("api_version invalid"), 400
コード例 #10
0
ファイル: rest_call.py プロジェクト: HelperLine/backend
    def put(self):

        # Modify an accepted call (reject, fulfill, comment)

        params_dict = routing.get_params_dict(request, print_out=True)

        authentication_result = tokening.check_helper_api_key(params_dict)
        if authentication_result["status"] != "ok":
            return formatting.postprocess_response(authentication_result)

        validation_result = validating.validate_edit_call(params_dict)
        if validation_result["status"] != "ok":
            return formatting.postprocess_response(validation_result)

        result_dict = call_scripts.modify_call(params_dict)
        return formatting.postprocess_response(result_dict)
コード例 #11
0
def route_authentication_login(api_version, account_type):

    if api_version == "v1":

        params_dict = routing.get_params_dict(request)

        # Artificial delay to further prevent brute forcing
        time.sleep(0.05)

        email = params_dict['email']
        password = params_dict['password']
        api_key = params_dict['api_key']

        if account_type == "helper":

            # Initial login
            if email is not None and password is not None:
                login_result = helper_login_password(email, password)
                return formatting.postprocess_response(login_result)

            # Automatic re-login from webapp
            elif email is not None and api_key is not None:
                login_result = helper_login_api_key(email, api_key)
                return formatting.postprocess_response(login_result)

        elif account_type == "admin":

            # initial login
            if email is not None and password is not None:
                login_result = admin_login_password(email, password)
                return formatting.postprocess_response(login_result)

            # automatic re-login from webapp
            elif email is not None and api_key is not None:
                login_result = admin_login_api_key(email, api_key)
                return formatting.postprocess_response(login_result)

        else:
            return formatting.status("account_type invalid"), 400

        return formatting.status('email/password/api_key missing'), 400

    else:
        # Programming Error
        return formatting.status("api_version invalid"), 400
コード例 #12
0
ファイル: hotline_routes.py プロジェクト: HelperLine/backend
def route_hotline_question1(api_version, language):
    # STEP 2) Local Help or Independet of Location?
    #         if local: redirect to zip_code captcha
    #         else: generate caller and call record -> redirect to feedback captcha

    resp = VoiceResponse()

    if language not in ["de", "en-gb"]:
        resp.redirect('/v1/hotline/error/language')
        return str(resp)

    if api_version == "v1":
        if 'Digits' in request.values:
            choice = request.values['Digits']

            if choice == '1':
                resp.redirect(f'/{api_version}/hotline/{language}/question2')
                return str(resp)
            elif choice == '2':
                caller_id = hotline_scripts.add_caller(
                    routing.get_params_dict(request)['Caller'])['caller_id']
                call_id = hotline_scripts.add_call(
                    caller_id,
                    formatting.twilio_language_to_string(language),
                    call_type='global')['call_id']
                resp.redirect(
                    f'/{api_version}/hotline/{language}/question3/{call_id}')
                return str(resp)
            else:
                resp.say(hotline_translation['unknown_option'][language],
                         voice='woman',
                         language=language)

        gather = Gather(num_digits=1)
        gather.say(hotline_translation['question_1_text_1'][language],
                   voice='woman',
                   language=language)
        resp.append(gather)

        resp.redirect(f'/{api_version}/hotline/{language}/question1')
    else:
        resp.redirect('/v1/hotline/error/api_version')

    return str(resp)
コード例 #13
0
ファイル: hotline_routes.py プロジェクト: HelperLine/backend
def route_hotline_question2(api_version, language):
    # STEP 2.5) Enter zip code -> generate caller and call record

    resp = VoiceResponse()

    if language not in ["de", "en-gb"]:
        resp.redirect('/v1/hotline/error/language')
        return str(resp)

    if api_version == "v1":
        gather = Gather(num_digits=6, finish_on_key='#')

        if 'Digits' in request.values:

            zip_code = request.values['Digits']
            finished_on_key = request.values['FinishedOnKey']

            if len(zip_code) == 5 and finished_on_key == '#':

                caller_id = hotline_scripts.add_caller(
                    routing.get_params_dict(request)['Caller'])['caller_id']
                call_id = hotline_scripts.add_call(
                    caller_id,
                    formatting.twilio_language_to_string(language),
                    call_type='local',
                    zip_code=zip_code)['call_id']
                resp.redirect(
                    f'/{api_version}/hotline/{language}/question3/{call_id}')
                return str(resp)

        gather.say(hotline_translation['question_2_text_1'][language],
                   voice='woman',
                   language=language)
        resp.append(gather)

        resp.redirect(f'/{api_version}/hotline/{language}/question2')
    else:
        resp.redirect('/v1/hotline/error/api_version')

    return str(resp)
コード例 #14
0
def route_database_fetchall(api_version):
    if api_version == "v1":

        params_dict = routing.get_params_dict(request)

        authentication_result = tokening.check_helper_api_key(
            params_dict,
            new_api_key=(os.getenv("ENVIRONMENT") == "production"))
        if authentication_result["status"] != "ok":
            return formatting.postprocess_response(authentication_result)

        account_dict = account_scripts.get_account(params_dict['email'])
        calls_dict = call_scripts.get_calls(params_dict['email'])
        filter_dict = filter_scripts.get_filter(params_dict['email'])
        forward_dict = forward_scripts.get_forward(params_dict['email'])

        for result_dict in [
                account_dict, calls_dict, filter_dict, forward_dict
        ]:
            if result_dict["status"] != "ok":
                return formatting.postprocess_response(result_dict)

        performance_dict = performance_scripts.get_performance(
            account_dict["account"]["zip_code"])

        result_dict = formatting.status(
            "ok",
            account=account_dict["account"],
            calls=calls_dict["calls"],
            filter=filter_dict["filter"],
            forward=forward_dict["forward"],
            performance=performance_dict["performance"])
        return formatting.postprocess_response(
            result_dict, new_api_key=authentication_result['api_key'])

    else:
        return formatting.status("api_version invalid"), 400