From 91fe68eed492e82530cf681d40326513a9a3c533 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Thu, 9 Apr 2020 17:50:05 +0100 Subject: [PATCH] WIP read firetext response codes --- app/celery/process_sms_client_response_tasks.py | 4 ++-- app/clients/sms/firetext.py | 16 ++++++++++++++++ app/notifications/notifications_sms_callback.py | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/celery/process_sms_client_response_tasks.py b/app/celery/process_sms_client_response_tasks.py index 1ee86634e..c9950609e 100644 --- a/app/celery/process_sms_client_response_tasks.py +++ b/app/celery/process_sms_client_response_tasks.py @@ -7,7 +7,7 @@ from notifications_utils.template import SMSMessageTemplate from app import notify_celery, statsd_client from app.clients import ClientException -from app.clients.sms.firetext import get_firetext_responses +from app.clients.sms.firetext import get_firetext_responses, get_message_status_from_firetext_code from app.clients.sms.mmg import get_mmg_responses from app.celery.service_callback_tasks import send_delivery_status_to_service, create_delivery_status_callback_data from app.config import QueueNames @@ -24,7 +24,7 @@ sms_response_mapper = { @notify_celery.task(bind=True, name="process-sms-client-response", max_retries=5, default_retry_delay=300) @statsd(namespace="tasks") -def process_sms_client_response(self, status, provider_reference, client_name): +def process_sms_client_response(self, status, provider_reference, client_name, code=None): # validate reference try: uuid.UUID(provider_reference, version=4) diff --git a/app/clients/sms/firetext.py b/app/clients/sms/firetext.py index feb81ce3e..2cc24a67c 100644 --- a/app/clients/sms/firetext.py +++ b/app/clients/sms/firetext.py @@ -19,11 +19,27 @@ firetext_responses = { '2': 'pending' } +firetext_codes = { + '101': 'permanent-failure', # Unknown Subscriber + '102': 'temporary-failure', # Absent Subscriber + '103': 'temporary-failure', # Subscriber Busy + '104': 'temporary-failure', # No Subscriber Memory + '201': 'permanent-failure', # Invalid Number + '301': 'permanent-failure', # SMS Not Supported + '302': 'temporary-failure', # SMS Not Supported + '401': 'permanent-failure', # Message Rejected + '900': 'temporary-failure', # Routing Error +} + def get_firetext_responses(status): return firetext_responses[status] +def get_message_status_from_firetext_code(code): + return firetext_codes[code] + + class FiretextClientResponseException(SmsClientResponseException): def __init__(self, response, exception): status_code = response.status_code if response is not None else 504 diff --git a/app/notifications/notifications_sms_callback.py b/app/notifications/notifications_sms_callback.py index afc705846..2c623a846 100644 --- a/app/notifications/notifications_sms_callback.py +++ b/app/notifications/notifications_sms_callback.py @@ -48,6 +48,7 @@ def process_firetext_response(): raise InvalidRequest(errors, status_code=400) status = request.form.get('status') + code = request.form.get('code') provider_reference = request.form.get('reference') safe_to_log = dict(request.form).copy() @@ -57,7 +58,7 @@ def process_firetext_response(): ) process_sms_client_response.apply_async( - [status, provider_reference, client_name], + [status, provider_reference, client_name, code], queue=QueueNames.SMS_CALLBACKS, )