Files
notifications-api/app/notifications/notifications_sms_callback.py
Rebecca Law 6fb4e16067 Added logging to show the entire form posted to us by the SMS client providers.
This can be useful information when debugging what happened to a notificaiton.
Recently there was a discrepancy between the failure type used by each provider for a particular number, this logging would have helped.
2017-07-12 14:19:39 +01:00

56 lines
2.4 KiB
Python

from flask import Blueprint
from flask import current_app
from flask import json
from flask import request, jsonify
from app.errors import InvalidRequest, register_errors
from app.notifications.process_client_response import validate_callback_data, process_sms_client_response
sms_callback_blueprint = Blueprint("sms_callback", __name__, url_prefix="/notifications/sms")
register_errors(sms_callback_blueprint)
@sms_callback_blueprint.route('/mmg', methods=['POST'])
def process_mmg_response():
client_name = 'MMG'
data = json.loads(request.data)
errors = validate_callback_data(data=data,
fields=['status', 'CID'],
client_name=client_name)
if errors:
raise InvalidRequest(errors, status_code=400)
success, errors = process_sms_client_response(status=str(data.get('status')),
reference=data.get('CID'),
client_name=client_name)
current_app.logger.info(
"Full delivery response from {} for notification: {}\n{}".format(client_name, request.form.get('reference'),
request.form))
if errors:
raise InvalidRequest(errors, status_code=400)
else:
return jsonify(result='success', message=success), 200
@sms_callback_blueprint.route('/firetext', methods=['POST'])
def process_firetext_response():
client_name = 'Firetext'
errors = validate_callback_data(data=request.form,
fields=['status', 'reference'],
client_name=client_name)
if errors:
raise InvalidRequest(errors, status_code=400)
status = request.form.get('status')
current_app.logger.info(
"Full delivery response from {} for notification: {}\n{}".format(client_name, request.form.get('reference'),
request.form))
success, errors = process_sms_client_response(status=status,
reference=request.form.get('reference'),
client_name=client_name)
if errors:
raise InvalidRequest(errors, status_code=400)
else:
return jsonify(result='success', message=success), 200