2021-03-04 17:47:13 +01:00
|
|
|
# standard imports
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
# third-party imports
|
|
|
|
import phonenumbers
|
|
|
|
|
|
|
|
# local imports
|
2021-04-19 10:44:40 +02:00
|
|
|
from cic_ussd.db.models.account import Account
|
2021-03-04 17:47:13 +01:00
|
|
|
|
|
|
|
|
2021-06-23 08:44:01 +02:00
|
|
|
class E164Format:
|
|
|
|
region = None
|
|
|
|
|
|
|
|
|
2021-03-04 17:47:13 +01:00
|
|
|
def process_phone_number(phone_number: str, region: str):
|
|
|
|
"""This function parses any phone number for the provided region
|
|
|
|
:param phone_number: A string with a phone number.
|
|
|
|
:type phone_number: str
|
|
|
|
:param region: Caller defined region
|
|
|
|
:type region: str
|
|
|
|
:return: The parsed phone number value based on the defined region
|
|
|
|
:rtype: str
|
|
|
|
"""
|
|
|
|
if not isinstance(phone_number, str):
|
|
|
|
try:
|
|
|
|
phone_number = str(int(phone_number))
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
phone_number_object = phonenumbers.parse(phone_number, region)
|
|
|
|
parsed_phone_number = phonenumbers.format_number(phone_number_object, phonenumbers.PhoneNumberFormat.E164)
|
|
|
|
|
|
|
|
return parsed_phone_number
|
|
|
|
|
2021-06-07 10:02:03 +02:00
|
|
|
class Support:
|
|
|
|
phone_number = None
|