From 6268d9547c48fc36326823c94ceaaf32aef266f6 Mon Sep 17 00:00:00 2001 From: KlemenSpruk Date: Wed, 25 Oct 2023 15:07:25 +0200 Subject: [PATCH] do not call services if not needed --- .../notifications/base/channels/integrations/aws_ses.py | 2 ++ .../base/channels/integrations/aws_sns_single_sms.py | 2 ++ .../notifications/base/channels/integrations/nexmo_sms.py | 3 +++ .../notifications/base/channels/integrations/t2.py | 2 ++ 4 files changed, 9 insertions(+) diff --git a/django_project_base/notifications/base/channels/integrations/aws_ses.py b/django_project_base/notifications/base/channels/integrations/aws_ses.py index 73bc71bc..c88a8a35 100644 --- a/django_project_base/notifications/base/channels/integrations/aws_ses.py +++ b/django_project_base/notifications/base/channels/integrations/aws_ses.py @@ -80,6 +80,8 @@ def enqueue_dlr_request(self, pk: str): DeliveryReport.objects.filter(pk=pk).update(status=DeliveryReport.Status.DELIVERED) def client_send(self, sender: str, recipient: Recipient, msg: dict, dlr_id: str): + if not recipient.email: + return res = ( boto3.Session( aws_access_key_id=self.key_id, diff --git a/django_project_base/notifications/base/channels/integrations/aws_sns_single_sms.py b/django_project_base/notifications/base/channels/integrations/aws_sns_single_sms.py index d77dac53..eac79b5f 100644 --- a/django_project_base/notifications/base/channels/integrations/aws_sns_single_sms.py +++ b/django_project_base/notifications/base/channels/integrations/aws_sns_single_sms.py @@ -41,6 +41,8 @@ def validate_send(self, response: dict): assert is_success(response.get("ResponseMetadata", {}).get("HTTPStatusCode", 500)) def client_send(self, sender: str, recipient: Recipient, msg: str, dlr_id: str): + if not recipient.phone_number: + return smsattrs = { "AWS.SNS.SMS.SenderID": {"DataType": "String", "StringValue": sender.replace(" ", "-")}, "AWS.SNS.SMS.SMSType": {"DataType": "String", "StringValue": "Promotional"}, diff --git a/django_project_base/notifications/base/channels/integrations/nexmo_sms.py b/django_project_base/notifications/base/channels/integrations/nexmo_sms.py index 100956ed..fd683e1b 100644 --- a/django_project_base/notifications/base/channels/integrations/nexmo_sms.py +++ b/django_project_base/notifications/base/channels/integrations/nexmo_sms.py @@ -43,6 +43,9 @@ def client_send(self, sender: str, recipient: Recipient, msg: str, dlr_id: str): if not rec: return + if not rec[0]: + return + params: dict = { "api_key": self.api_key, "api_secret": self.api_secret, diff --git a/django_project_base/notifications/base/channels/integrations/t2.py b/django_project_base/notifications/base/channels/integrations/t2.py index 910b10a8..f4d01014 100644 --- a/django_project_base/notifications/base/channels/integrations/t2.py +++ b/django_project_base/notifications/base/channels/integrations/t2.py @@ -294,6 +294,8 @@ def ensure_credentials(self, extra_data): assert len(self.url) > 0, "T2_PASSWORD is required" def client_send(self, sender: str, recipient: Recipient, msg: str, dlr_id: str): + if not recipient.phone_number: + return basic_auth = HTTPBasicAuth(self.username, self.password) response = requests.post( f"{self.url}{self.endpoint_one}",