Description
User Story - Business Need
International SMS is not functional currently. Create new method(s) that use the phonenumbers library to validate the number is possible, normalize it, and identify which country it is for in a method that can be called at any point in the notification-api (not just at the initial request).
Do not reuse the existing methods. Replace existing notification-api code with these new methods and delete the old methods.
Country digit/code is not going to be used at this time, but a method should be written because we know it is necessary and it is cumbersome to develop in notification-utils. Quicker to knock it out now.
- Ticket is understood, and QA has been contacted (if the ticket has a QA label).
User Story(ies)
As a VA Notify dev
I want phone number validation to be maintainable
So that we can expand functionality
Additional Info and Resources
notification-api
does certain things with notification-utils
. Do not follow the structure of utils if it is overly complex.
This repo incorrectly uses phonenumbers, or perhaps the new functions did not exist at the time. Regardless, please leverage the below guidance when thinking about how to build out this functionality.
Simple POC script:
import phonenumbers
from phonenumbers.phonenumberutil import region_code_for_number
def number_details(number):
try:
print(f'Input number: {number}')
pn = phonenumbers.parse(number, None)
except phonenumbers.phonenumberutil.NumberParseException as e:
print(f'Could not parse number: {number} due to : {e}')
else:
print(f'Country Code: {pn.country_code}/{region_code_for_number(pn)} | Number: {pn.national_number} | Is possible: {phonenumbers.is_possible_number(pn)}')
fpn = phonenumbers.format_number(pn, phonenumbers.PhoneNumberFormat.E164)
print(f'E164 formatted number: {fpn}\n')
numbers = (
'+1613-238-5335', # Canada
'+33 825 30 05 00', # France
'+61396694916', # Australia
'+33143122222', # France
'+[44] (0)20 7499-9000', # UK
'+1671-647-4000', # Guam
'+1(242) 322-1181', # Bahamas
'+1108675309', # Impossible but looks real
'[44] (0)20 7499-9000', # Missing +
)
for num in numbers:
number_details(num)
Result:
Input number: +1613-238-5335
Country Code: 1/CA | Number: 6132385335 | Is possible: True
E164 formatted number: +16132385335
Input number: +33 825 30 05 00
Country Code: 33/FR | Number: 825300500 | Is possible: True
E164 formatted number: +33825300500
Input number: +61396694916
Country Code: 61/AU | Number: 396694916 | Is possible: True
E164 formatted number: +61396694916
Input number: +33143122222
Country Code: 33/FR | Number: 143122222 | Is possible: True
E164 formatted number: +33143122222
Input number: +[44] (0)20 7499-9000
Country Code: 44/GB | Number: 2074999000 | Is possible: True
E164 formatted number: +442074999000
Input number: +1671-647-4000
Country Code: 1/GU | Number: 6716474000 | Is possible: True
E164 formatted number: +16716474000
Input number: +1(242) 322-1181
Country Code: 1/BS | Number: 2423221181 | Is possible: True
E164 formatted number: +12423221181
Input number: +1108675309
Country Code: 1/None | Number: 108675309 | Is possible: False
E164 formatted number: +1108675309
Input number: [44] (0)20 7499-9000
Could not parse number: [44] (0)20 7499-9000 due to : (0) Missing or invalid default region.
Acceptance Criteria
- No functionality has been lost
- If feasible, an object (such as a class/dataclass) is used to store things such as the formatted number, country code, etc.
- A method exists that can validate a phone number
- A method exists that can E.164 format a number
- A method exists that can return country digit and country code (unit tested, no integration tests)
- SMS still functions in the notification-api after these are implemented and old methods removed
- This work is added to the sprint review slide deck (key win bullet point and demo slide)
QA Considerations
A variety of international numbers were tested above. Please consider any other cases when talking to the dev. Country digit/code test will not be capable of integration testing at this time.
Potential Dependencies
None
Activity