2017-03-16 18:15:49 +00:00
|
|
|
from flask import Blueprint
|
2017-07-12 14:19:39 +01:00
|
|
|
from flask import current_app
|
2017-03-16 18:15:49 +00:00
|
|
|
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
|
|
|
|
|
|
2017-03-17 16:21:41 +00:00
|
|
|
sms_callback_blueprint = Blueprint("sms_callback", __name__, url_prefix="/notifications/sms")
|
2017-03-16 18:15:49 +00:00
|
|
|
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)
|
2017-07-12 14:19:39 +01:00
|
|
|
|
2017-07-12 15:32:59 +01:00
|
|
|
safe_to_log = data.copy()
|
|
|
|
|
safe_to_log.pop("MSISDN")
|
As Notify matures we probably need less logging, especially to report happy path events.
This PR is a proposal to reduce the average messages we see for a single notification from about 7 messages to 2.
Messaging would change to something like this:
February 2nd 2018, 15:39:05.885 Full delivery response from Firetext for notification: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
{'status': ['0'], 'reference': ['8eda51d5-cd82-4569-bfc9-d5570cdf2126'], 'time': ['2018-02-02 15:39:01'], 'code': ['000']}
February 2nd 2018, 15:39:05.885 Firetext callback return status of 0 for reference: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
February 2nd 2018, 15:38:57.727 SMS 8eda51d5-cd82-4569-bfc9-d5570cdf2126 sent to provider firetext at 2018-02-02 15:38:56.716814
February 2nd 2018, 15:38:56.727 Starting sending SMS 8eda51d5-cd82-4569-bfc9-d5570cdf2126 to provider at 2018-02-02 15:38:56.408181
February 2nd 2018, 15:38:56.727 Firetext request for 8eda51d5-cd82-4569-bfc9-d5570cdf2126 finished in 0.30376038211397827
February 2nd 2018, 15:38:49.449 sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 created at 2018-02-02 15:38:48.439113
February 2nd 2018, 15:38:49.449 sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 sent to the priority-tasks queue for delivery
To somthing like this:
February 2nd 2018, 15:39:05.885 Firetext callback return status of 0 for reference: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
February 2nd 2018, 15:38:49.449 sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 created at 2018-02-02 15:38:48.439113
2018-02-02 15:55:25 +00:00
|
|
|
current_app.logger.debug(
|
2017-07-12 15:32:59 +01:00
|
|
|
"Full delivery response from {} for notification: {}\n{}".format(client_name, request.form.get('CID'),
|
2017-07-12 15:49:43 +01:00
|
|
|
safe_to_log))
|
2017-03-16 18:15:49 +00:00
|
|
|
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)
|
2017-07-12 15:32:59 +01:00
|
|
|
safe_to_log = dict(request.form).copy()
|
|
|
|
|
safe_to_log.pop('mobile')
|
As Notify matures we probably need less logging, especially to report happy path events.
This PR is a proposal to reduce the average messages we see for a single notification from about 7 messages to 2.
Messaging would change to something like this:
February 2nd 2018, 15:39:05.885 Full delivery response from Firetext for notification: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
{'status': ['0'], 'reference': ['8eda51d5-cd82-4569-bfc9-d5570cdf2126'], 'time': ['2018-02-02 15:39:01'], 'code': ['000']}
February 2nd 2018, 15:39:05.885 Firetext callback return status of 0 for reference: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
February 2nd 2018, 15:38:57.727 SMS 8eda51d5-cd82-4569-bfc9-d5570cdf2126 sent to provider firetext at 2018-02-02 15:38:56.716814
February 2nd 2018, 15:38:56.727 Starting sending SMS 8eda51d5-cd82-4569-bfc9-d5570cdf2126 to provider at 2018-02-02 15:38:56.408181
February 2nd 2018, 15:38:56.727 Firetext request for 8eda51d5-cd82-4569-bfc9-d5570cdf2126 finished in 0.30376038211397827
February 2nd 2018, 15:38:49.449 sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 created at 2018-02-02 15:38:48.439113
February 2nd 2018, 15:38:49.449 sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 sent to the priority-tasks queue for delivery
To somthing like this:
February 2nd 2018, 15:39:05.885 Firetext callback return status of 0 for reference: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
February 2nd 2018, 15:38:49.449 sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 created at 2018-02-02 15:38:48.439113
2018-02-02 15:55:25 +00:00
|
|
|
current_app.logger.debug(
|
2017-07-12 14:19:39 +01:00
|
|
|
"Full delivery response from {} for notification: {}\n{}".format(client_name, request.form.get('reference'),
|
2017-07-12 15:32:59 +01:00
|
|
|
safe_to_log))
|
|
|
|
|
success, errors = process_sms_client_response(status=request.form.get('status'),
|
2017-03-16 18:15:49 +00:00
|
|
|
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
|