diff --git a/app/clients/sms/twilio.py b/app/clients/sms/twilio.py index a1c876bdeb..96cfbc0f7f 100644 --- a/app/clients/sms/twilio.py +++ b/app/clients/sms/twilio.py @@ -240,15 +240,14 @@ def translate_delivery_status( parsed_dict = parse_qs(decoded_msg) message_sid = parsed_dict['MessageSid'][0] twilio_delivery_status = parsed_dict['MessageStatus'][0] + error_code_data = parsed_dict.get('ErrorCode', None) if twilio_delivery_status not in self.twilio_notify_status_map: value_error = f'Invalid Twilio delivery status: {twilio_delivery_status}' raise ValueError(value_error) - if 'ErrorCode' in parsed_dict and ( - twilio_delivery_status == 'failed' or twilio_delivery_status == 'undelivered' - ): - error_code = parsed_dict['ErrorCode'][0] + if error_code_data and (twilio_delivery_status == 'failed' or twilio_delivery_status == 'undelivered'): + error_code = error_code_data[0] if error_code in self.twilio_error_code_map: notify_delivery_status: TwilioStatus = self.twilio_error_code_map[error_code] @@ -259,10 +258,10 @@ def translate_delivery_status( notify_delivery_status: TwilioStatus = self.twilio_notify_status_map[twilio_delivery_status] else: # Logic not being changed, just want to log this for now - if 'ErrorCode' in parsed_dict: + if error_code_data: self.logger.warning( 'Error code: %s existed but status for message: %s was not failed nor undelivered', - error_code, + error_code_data[0], message_sid, ) notify_delivery_status: TwilioStatus = self.twilio_notify_status_map[twilio_delivery_status] diff --git a/app/va/va_profile/va_profile_client.py b/app/va/va_profile/va_profile_client.py index ff45ad7be3..d4405d3a0d 100644 --- a/app/va/va_profile/va_profile_client.py +++ b/app/va/va_profile/va_profile_client.py @@ -31,6 +31,8 @@ 'sms': 'Text', } +# source for valid phone types for SMS delivery: +# https://docs.aws.amazon.com/pinpoint/latest/developerguide/validate-phone-numbers.html#validate-phone-numbers-example-responses VALID_PHONE_TYPES_FOR_SMS_DELIVERY = [ 0, # "MOBILE" 2, # "VOIP"