diff --git a/app/clients/sms/aws_pinpoint.py b/app/clients/sms/aws_pinpoint.py index 918e0b5937..b2b5373e4c 100644 --- a/app/clients/sms/aws_pinpoint.py +++ b/app/clients/sms/aws_pinpoint.py @@ -26,7 +26,7 @@ def send_sms(self, to, content, reference, multi=True, sender=None): messageType = "TRANSACTIONAL" matched = False - for match in phonenumbers.PhoneNumberMatcher(to, "US"): + for match in phonenumbers.PhoneNumberMatcher(to, "US"): # SJA why is this a loop? matched = True to = phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.E164) destinationNumber = to @@ -53,8 +53,7 @@ def send_sms(self, to, content, reference, multi=True, sender=None): self.current_app.logger.info("AWS Pinpoint request finished in {}".format(elapsed_time)) self.statsd_client.timing("clients.pinpoint.request-time", elapsed_time) self.statsd_client.incr("clients.pinpoint.success") - - return response['MessageId'] + return response['MessageId'] if not matched: self.statsd_client.incr("clients.pinpoint.error") diff --git a/app/config.py b/app/config.py index 19e4aeef9e..dd374bcd55 100644 --- a/app/config.py +++ b/app/config.py @@ -265,6 +265,7 @@ class Config(object): AWS_SES_SECRET_KEY = os.getenv("AWS_SES_SECRET_KEY") AWS_PINPOINT_REGION = os.getenv("AWS_PINPOINT_REGION", "us-west-2") AWS_PINPOINT_POOL_ID = os.getenv("AWS_PINPOINT_POOL_ID", None) + AWS_PINPOINT_TEMPLATE_IDS = env.list("AWS_PINPOINT_TEMPLATE_IDS", []) AWS_US_TOLL_FREE_NUMBER = os.getenv("AWS_US_TOLL_FREE_NUMBER") CSV_UPLOAD_BUCKET_NAME = os.getenv("CSV_UPLOAD_BUCKET_NAME", "notification-alpha-canada-ca-csv-upload") ASSET_DOMAIN = os.getenv("ASSET_DOMAIN", "assets.notification.canada.ca") diff --git a/app/delivery/send_to_providers.py b/app/delivery/send_to_providers.py index 76b72d10fb..3eaded502c 100644 --- a/app/delivery/send_to_providers.py +++ b/app/delivery/send_to_providers.py @@ -68,6 +68,7 @@ def send_sms_to_provider(notification): notification.id, notification.international, notification.reply_to_text, + template_id=notification.template_id, ) template_dict = dao_get_template_by_id(notification.template_id, notification.template_version).__dict__ @@ -334,7 +335,10 @@ def update_notification_to_sending(notification, provider): dao_update_notification(notification) -def provider_to_use(notification_type, notification_id, international=False, sender=None): +def provider_to_use(notification_type, notification_id, international=False, sender=None, template_id=None): + if notification_type == SMS_TYPE and template_id is not None and str(template_id) in Config.AWS_PINPOINT_TEMPLATE_IDS: + return clients.get_client_by_name_and_type('pinpoint', SMS_TYPE) + active_providers_in_order = [ p for p in get_provider_details_by_notification_type(notification_type, international) if p.active ] @@ -343,11 +347,7 @@ def provider_to_use(notification_type, notification_id, international=False, sen current_app.logger.error("{} {} failed as no active providers".format(notification_type, notification_id)) raise Exception("No active {} providers".format(notification_type)) - # return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type) - - if notification_type == SMS_TYPE: - return clients.get_client_by_name_and_type('pinpoint', notification_type) - + return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type) def get_html_email_options(service: Service):