mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 06:33:12 -04:00
WIP: adding delivery receipt endpoint for mmg
This commit is contained in:
@@ -9,8 +9,6 @@ from requests import request, RequestException, HTTPError
|
|||||||
from app.clients import ClientResponse, STATISTICS_DELIVERED, STATISTICS_FAILURE
|
from app.clients import ClientResponse, STATISTICS_DELIVERED, STATISTICS_FAILURE
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class FiretextResponses(ClientResponse):
|
class FiretextResponses(ClientResponse):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
ClientResponse.__init__(self)
|
ClientResponse.__init__(self)
|
||||||
|
|||||||
@@ -1,7 +1,44 @@
|
|||||||
from flask import current_app
|
from flask import current_app
|
||||||
from monotonic import monotonic
|
from monotonic import monotonic
|
||||||
from requests import request, RequestException, HTTPError
|
from requests import (request, RequestException, HTTPError)
|
||||||
from app.clients.sms import SmsClient
|
|
||||||
|
from app.clients import (ClientResponse, STATISTICS_DELIVERED, STATISTICS_FAILURE)
|
||||||
|
from app.clients.sms import (SmsClient, SmsClientException)
|
||||||
|
|
||||||
|
|
||||||
|
class FiretextResponses(ClientResponse):
|
||||||
|
def __init__(self):
|
||||||
|
ClientResponse.__init__(self)
|
||||||
|
self.__response_model__ = {
|
||||||
|
'0': {
|
||||||
|
"message": 'Delivered',
|
||||||
|
"notification_statistics_status": STATISTICS_DELIVERED,
|
||||||
|
"success": True,
|
||||||
|
"notification_status": 'delivered'
|
||||||
|
},
|
||||||
|
'1': {
|
||||||
|
"message": 'Declined',
|
||||||
|
"success": False,
|
||||||
|
"notification_statistics_status": STATISTICS_FAILURE,
|
||||||
|
"notification_status": 'failed'
|
||||||
|
},
|
||||||
|
'2': {
|
||||||
|
"message": 'Undelivered (Pending with Network)',
|
||||||
|
"success": False,
|
||||||
|
"notification_statistics_status": None,
|
||||||
|
"notification_status": 'sent'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MMGClientException(SmsClientException):
|
||||||
|
def __init__(self, error_response):
|
||||||
|
self.code = error_response['Error']
|
||||||
|
self.description = error_response['Description']
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "Code {} description {}".format(self.code, self.description)
|
||||||
|
|
||||||
|
|
||||||
class MMGClient(SmsClient):
|
class MMGClient(SmsClient):
|
||||||
@@ -30,6 +67,10 @@ class MMGClient(SmsClient):
|
|||||||
try:
|
try:
|
||||||
response = request("POST", "https://www.mmgrp.co.uk/API/json/api.php",
|
response = request("POST", "https://www.mmgrp.co.uk/API/json/api.php",
|
||||||
data=data)
|
data=data)
|
||||||
|
if response.status_code != 200:
|
||||||
|
error = response.json
|
||||||
|
raise MMGClientException(error)
|
||||||
|
response.raise_for_status()
|
||||||
except RequestException as e:
|
except RequestException as e:
|
||||||
api_error = HTTPError.create(e)
|
api_error = HTTPError.create(e)
|
||||||
current_app.logger.error(
|
current_app.logger.error(
|
||||||
@@ -45,4 +86,3 @@ class MMGClient(SmsClient):
|
|||||||
elapsed_time = monotonic() - start_time
|
elapsed_time = monotonic() - start_time
|
||||||
current_app.logger.info("MMG request finished in {}".format(elapsed_time))
|
current_app.logger.info("MMG request finished in {}".format(elapsed_time))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,13 @@ def is_not_a_notification(source):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@notifications.route('/notifications/sms/mmg', methods=['POST'])
|
||||||
|
def process_mmg_response():
|
||||||
|
print('here')
|
||||||
|
current_app.logger.info('MMG client callback json{}'.format(request.json))
|
||||||
|
current_app.logger.info('MMG client callback form{}'.format(request.form))
|
||||||
|
|
||||||
|
|
||||||
@notifications.route('/notifications/sms/firetext', methods=['POST'])
|
@notifications.route('/notifications/sms/firetext', methods=['POST'])
|
||||||
def process_firetext_response():
|
def process_firetext_response():
|
||||||
if 'status' not in request.form:
|
if 'status' not in request.form:
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class Config(object):
|
|||||||
SQLALCHEMY_RECORD_QUERIES = True
|
SQLALCHEMY_RECORD_QUERIES = True
|
||||||
VERIFY_CODE_FROM_EMAIL_ADDRESS = os.environ['VERIFY_CODE_FROM_EMAIL_ADDRESS']
|
VERIFY_CODE_FROM_EMAIL_ADDRESS = os.environ['VERIFY_CODE_FROM_EMAIL_ADDRESS']
|
||||||
NOTIFY_EMAIL_DOMAIN = os.environ['NOTIFY_EMAIL_DOMAIN']
|
NOTIFY_EMAIL_DOMAIN = os.environ['NOTIFY_EMAIL_DOMAIN']
|
||||||
NOTIFY_FROM_NUMBER= os.environ['NOTIFY_FROM_NUMBER']
|
NOTIFY_FROM_NUMBER = os.environ['NOTIFY_FROM_NUMBER']
|
||||||
PAGE_SIZE = 50
|
PAGE_SIZE = 50
|
||||||
|
|
||||||
BROKER_URL = 'sqs://'
|
BROKER_URL = 'sqs://'
|
||||||
|
|||||||
@@ -18,3 +18,5 @@ export TWILIO_NUMBER="test"
|
|||||||
export FIRETEXT_API_KEY="Firetext"
|
export FIRETEXT_API_KEY="Firetext"
|
||||||
export FIRETEXT_NUMBER="Firetext"
|
export FIRETEXT_NUMBER="Firetext"
|
||||||
export NOTIFY_EMAIL_DOMAIN="test.notify.com"
|
export NOTIFY_EMAIL_DOMAIN="test.notify.com"
|
||||||
|
export MMG_API_KEY='mmg-secret-key'
|
||||||
|
export NOTIFY_FROM_NUMBER='test'
|
||||||
Reference in New Issue
Block a user