Skip to content

Commit

Permalink
use Pinpoint for international numbers (#2198)
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels committed Jun 24, 2024
1 parent f8c086d commit 841f648
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
12 changes: 2 additions & 10 deletions app/delivery/send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def provider_to_use(
notification_type (str): SMS or EMAIL.
notification_id (UUID): id of notification. Just used for logging.
to (str, optional): recipient. Defaults to None.
international (bool, optional): Flags whether or not the message is outside of Canada and the US. Defaults to False.
international (bool, optional): Flags whether or not the message recipient is outside of Canada and the US. Defaults to False.
sender (str, optional): reply_to_text to use. Defaults to None.
template_id (str, optional): template_id to use. Defaults to None.
Expand All @@ -370,7 +370,6 @@ def provider_to_use(
has_dedicated_number = sender is not None and sender.startswith("+1")
cannot_determine_recipient_country = False
sending_to_us_number = False
sending_internationally = False
if to is not None:
match = next(iter(phonenumbers.PhoneNumberMatcher(to, "US")), None)
if match is None:
Expand All @@ -379,19 +378,12 @@ def provider_to_use(
phonenumbers.region_code_for_number(match.number) == "US"
): # The US is a special case that needs to send from a US toll free number
sending_to_us_number = True
elif (
phonenumbers.region_code_for_number(match.number) != "CA"
): # Currently Pinpoint is having issues sending to non-Canadian numbers.
sending_internationally = True

using_sc_pool_template = template_id is not None and str(template_id) in current_app.config["AWS_PINPOINT_SC_TEMPLATE_IDS"]

do_not_use_pinpoint = (
has_dedicated_number
or cannot_determine_recipient_country
or international # Defaulting back to SNS: it's not entirely clear what this flag is for. Not always set for international recipients.
or sending_to_us_number
or sending_internationally
or cannot_determine_recipient_country
or not current_app.config["AWS_PINPOINT_SC_POOL_ID"]
or ((not current_app.config["AWS_PINPOINT_DEFAULT_POOL_ID"]) and not using_sc_pool_template)
)
Expand Down
11 changes: 0 additions & 11 deletions tests/app/delivery/test_send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,6 @@ def test_should_use_sns_for_sms_if_sending_to_the_US(self, restore_provider_deta
provider = send_to_providers.provider_to_use("sms", "1234", "+17065551234")
assert provider.name == "sns"

def test_should_use_sns_for_sms_if_sending_internationally(self, restore_provider_details, notify_api):
with set_config_values(
notify_api,
{
"AWS_PINPOINT_SC_POOL_ID": "sc_pool_id",
"AWS_PINPOINT_DEFAULT_POOL_ID": "default_pool_id",
},
):
provider = send_to_providers.provider_to_use("sms", "1234", "+4408456021111") # British Telecom test line
assert provider.name == "sns"

def test_should_use_sns_for_sms_if_match_fails(self, restore_provider_details, notify_api):
with set_config_values(
notify_api,
Expand Down

0 comments on commit 841f648

Please sign in to comment.