def get_user_number(service_id, notification_id): try: user_number = service_api_client.get_inbound_sms_by_id(service_id, notification_id)['user_number'] except HTTPError as e: if e.status_code != 404: raise user_number = notification_api_client.get_notification(service_id, notification_id)['to'] return format_phone_number_human_readable(user_number)
def get_user_number(service_id, notification_id): try: number = service_api_client.get_inbound_sms_by_id( service_id, notification_id)['user_number'] except HTTPError: notification = notification_api_client.get_notification( service_id, notification_id) number = notification['normalised_to'] # For old records normalised_to may be empty or it may be stored in the # old format (without storing the leading plus sign). If this is the # case, use the to field instead and create the E.164 format on the fly. if not number or not number.startswith('+'): number = notification['to'] return try_validate_and_format_phone_number(number)
def get_user_number(service_id, notification_id): try: number_e164 = service_api_client.get_inbound_sms_by_id( service_id, notification_id)['user_number'] except HTTPError: notification = notification_api_client.get_notification( service_id, notification_id) number_e164 = notification['normalised_to'] # For old records normalised_to may be empty or it may be stored in the # old format (without storing the leading plus sign). If this is the # case, use the to field instead and create the E.164 format on the fly. if not number_e164 or not number_e164.startswith('+'): try: number_e164 = validate_and_format_phone_number_and_allow_international( notification['to']) except Exception: return notification['to'] number = e164_to_phone_number(number_e164) return format_phone_number_human_readable(number)