2022-10-21 00:26:37 +00:00
|
|
|
from flask import Blueprint
|
2017-03-16 18:15:49 +00:00
|
|
|
|
2022-10-14 14:45:27 +00:00
|
|
|
from app.errors import register_errors
|
2017-03-16 18:15:49 +00:00
|
|
|
|
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)
|
|
|
|
|
|
2022-10-03 17:16:59 -07:00
|
|
|
# TODO SNS SMS delivery receipts delivered here
|
2022-12-22 08:44:04 -05:00
|
|
|
# This file should likely be deleted, since SNS does not use callback https calls
|
|
|
|
|
# Leaving for now to have an example of what jobs MMG did that we may want to replicate in the
|
|
|
|
|
# eventual SNS method.
|
2017-03-16 18:15:49 +00:00
|
|
|
|
2022-06-17 11:16:23 -07:00
|
|
|
# @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)
|
2017-03-16 18:15:49 +00:00
|
|
|
|
2022-06-17 11:16:23 -07:00
|
|
|
# status = str(data.get('status'))
|
|
|
|
|
# detailed_status_code = str(data.get('substatus'))
|
2020-05-27 18:03:55 +01:00
|
|
|
|
2022-06-17 11:16:23 -07:00
|
|
|
# provider_reference = data.get('CID')
|
2020-03-17 15:15:43 +00:00
|
|
|
|
2022-06-17 11:16:23 -07:00
|
|
|
# process_sms_client_response.apply_async(
|
|
|
|
|
# [status, provider_reference, client_name, detailed_status_code],
|
|
|
|
|
# queue=QueueNames.SMS_CALLBACKS,
|
|
|
|
|
# )
|
2017-07-12 14:19:39 +01:00
|
|
|
|
2022-06-17 11:16:23 -07:00
|
|
|
# return jsonify(result='success'), 200
|
2017-03-16 18:15:49 +00:00
|
|
|
|
|
|
|
|
|
2020-03-17 15:15:43 +00:00
|
|
|
def validate_callback_data(data, fields, client_name):
|
|
|
|
|
errors = []
|
|
|
|
|
for f in fields:
|
|
|
|
|
if not str(data.get(f, '')):
|
|
|
|
|
error = "{} callback failed: {} missing".format(client_name, f)
|
|
|
|
|
errors.append(error)
|
|
|
|
|
return errors if len(errors) > 0 else None
|