Skip to content

Commit

Permalink
Merge branch 'main' into hotfix-perf-celery-memory
Browse files Browse the repository at this point in the history
  • Loading branch information
coreycarvalho authored Dec 30, 2024
2 parents aa86293 + 719c7ad commit 5c40dd1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/clients/sms/aws_pinpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ def translate_delivery_status(
self.logger.error('Did not receive pinpoint delivery status as a string')
raise NonRetryableException(f'Incorrect datatype sent to pinpoint, {UNABLE_TO_TRANSLATE}')

if delivery_status_message.get('attributes', {}).get('destination_phone_number'):
# Replace the last 4 charactes with X. Works with empty strings
delivery_status_message['attributes']['destination_phone_number'] = (
f'{delivery_status_message["attributes"]["destination_phone_number"][:-4]}XXXX'
)
self.logger.info('Translate raw delivery status pinpoint: %s', delivery_status_message)

pinpoint_attributes = delivery_status_message['attributes']
event_type = delivery_status_message['event_type']
record_status = pinpoint_attributes['record_status']
Expand Down
2 changes: 2 additions & 0 deletions app/clients/sms/twilio.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ def translate_delivery_status(
raise NonRetryableException(f'Incorrect datatype sent to twilio, {UNABLE_TO_TRANSLATE}')

decoded_msg, parsed_dict = self._parse_twilio_message(delivery_status_message)
self.logger.info('Translate raw delivery status twilio: %s | %s', parsed_dict, delivery_status_message)

message_sid = parsed_dict['MessageSid'][0]
twilio_delivery_status = parsed_dict['MessageStatus'][0]
error_code = parsed_dict.get('ErrorCode', [])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime, timezone
from logging import getLogger
from uuid import uuid4

import pytest
Expand Down Expand Up @@ -489,6 +490,9 @@ def test_get_notification_notification_found(


def test_get_notification_platform_status(notify_api, sample_delivery_status_result_message):
twilio_client = TwilioSMSClient()
twilio_client.logger = getLogger('test')

# Happy path
expected_sms_status_record = SmsStatusRecord(
payload='RawDlrDoneDate=2303222338&SmsSid=SMxxx&SmsStatus=delivered&MessageStatus=delivered&To=%2B11111111111&MessageSid=SMyyy&AccountSid=ACzzz&From=%2B12223334444&ApiVersion=2010-04-01',
Expand All @@ -501,7 +505,7 @@ def test_get_notification_platform_status(notify_api, sample_delivery_status_res
provider_updated_at=datetime.strptime('2303222338', TwilioSMSClient.RAW_DLR_DONE_DATE_FMT),
)
assert expected_sms_status_record == get_notification_platform_status(
TwilioSMSClient(), sample_delivery_status_result_message['message']['body']
twilio_client, sample_delivery_status_result_message['message']['body']
)


Expand Down

0 comments on commit 5c40dd1

Please sign in to comment.