From 0da617d29ee675d760966c3fb0dc174326f732d0 Mon Sep 17 00:00:00 2001 From: Philip Wafula Date: Mon, 7 Jun 2021 08:02:03 +0000 Subject: [PATCH] Philip/add support phone number --- apps/cic-ussd/.config/app.ini | 1 + apps/cic-ussd/.config/test/app.ini | 1 + apps/cic-ussd/cic_ussd/phone_number.py | 4 ++++ apps/cic-ussd/cic_ussd/processor.py | 12 +++++++++++- .../runnable/daemons/cic_user_ussd_server.py | 4 +++- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/apps/cic-ussd/.config/app.ini b/apps/cic-ussd/.config/app.ini index 95a36052..1a0b5e4f 100644 --- a/apps/cic-ussd/.config/app.ini +++ b/apps/cic-ussd/.config/app.ini @@ -5,6 +5,7 @@ LOCALE_PATH=/usr/src/cic-ussd/var/lib/locale/ MAX_BODY_LENGTH=1024 PASSWORD_PEPPER=QYbzKff6NhiQzY3ygl2BkiKOpER8RE/Upqs/5aZWW+I= SERVICE_CODE=*483*46#,*483*061#,*384*96# +SUPPORT_PHONE_NUMBER=0757628885 [phone_number] REGION=KE diff --git a/apps/cic-ussd/.config/test/app.ini b/apps/cic-ussd/.config/test/app.ini index 38bc95c4..7ea1b696 100644 --- a/apps/cic-ussd/.config/test/app.ini +++ b/apps/cic-ussd/.config/test/app.ini @@ -5,6 +5,7 @@ LOCALE_PATH=var/lib/locale/ MAX_BODY_LENGTH=1024 PASSWORD_PEPPER=QYbzKff6NhiQzY3ygl2BkiKOpER8RE/Upqs/5aZWW+I= SERVICE_CODE=*483*46# +SUPPORT_PHONE_NUMBER=0757628885 [ussd] MENU_FILE=/usr/local/lib/python3.8/site-packages/cic_ussd/db/ussd_menu.json diff --git a/apps/cic-ussd/cic_ussd/phone_number.py b/apps/cic-ussd/cic_ussd/phone_number.py index 0a48b0d2..2c476fa0 100644 --- a/apps/cic-ussd/cic_ussd/phone_number.py +++ b/apps/cic-ussd/cic_ussd/phone_number.py @@ -41,3 +41,7 @@ def get_user_by_phone_number(phone_number: str) -> Optional[Account]: phone_number = process_phone_number(phone_number=phone_number, region='KE') user = Account.session.query(Account).filter_by(phone_number=phone_number).first() return user + + +class Support: + phone_number = None diff --git a/apps/cic-ussd/cic_ussd/processor.py b/apps/cic-ussd/cic_ussd/processor.py index 864cd53f..b483466c 100644 --- a/apps/cic-ussd/cic_ussd/processor.py +++ b/apps/cic-ussd/cic_ussd/processor.py @@ -19,7 +19,7 @@ from cic_ussd.db.models.ussd_session import UssdSession from cic_ussd.error import MetadataNotFoundError, SeppukuError from cic_ussd.menu.ussd_menu import UssdMenu from cic_ussd.metadata import blockchain_address_to_metadata_pointer -from cic_ussd.phone_number import get_user_by_phone_number +from cic_ussd.phone_number import get_user_by_phone_number, Support from cic_ussd.redis import cache_data, create_cached_data_key, get_cached_data from cic_ussd.state_machine import UssdStateMachine from cic_ussd.conversions import to_wei, from_wei @@ -466,6 +466,14 @@ def next_state(ussd_session: dict, user: Account, user_input: str) -> str: return new_state +def process_exit_invalid_menu_option(display_key: str, preferred_language: str): + return translation_for( + key=display_key, + preferred_language=preferred_language, + support_phone=Support.phone_number + ) + + def custom_display_text( display_key: str, menu_name: str, @@ -502,5 +510,7 @@ def custom_display_text( return process_account_statement(display_key=display_key, user=user, ussd_session=ussd_session) elif menu_name == 'display_user_metadata': return process_display_user_metadata(display_key=display_key, user=user) + elif menu_name == 'exit_invalid_menu_option': + return process_exit_invalid_menu_option(display_key=display_key, preferred_language=user.preferred_language) else: return translation_for(key=display_key, preferred_language=user.preferred_language) diff --git a/apps/cic-ussd/cic_ussd/runnable/daemons/cic_user_ussd_server.py b/apps/cic-ussd/cic_ussd/runnable/daemons/cic_user_ussd_server.py index 92c4147f..6aad181f 100644 --- a/apps/cic-ussd/cic_ussd/runnable/daemons/cic_user_ussd_server.py +++ b/apps/cic-ussd/cic_ussd/runnable/daemons/cic_user_ussd_server.py @@ -26,7 +26,7 @@ from cic_ussd.metadata.base import Metadata from cic_ussd.operations import (define_response_with_content, process_menu_interaction_requests, define_multilingual_responses) -from cic_ussd.phone_number import process_phone_number +from cic_ussd.phone_number import process_phone_number, Support from cic_ussd.processor import get_default_token_data from cic_ussd.redis import cache_data, create_cached_data_key, InMemoryStore from cic_ussd.requests import (get_request_endpoint, @@ -126,6 +126,8 @@ else: valid_service_codes = config.get('APP_SERVICE_CODE').split(",") +Support.phone_number = config.get('APP_SUPPORT_PHONE_NUMBER') + def application(env, start_response): """Loads python code for application to be accessible over web server