mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
New endpoint for delivery app to use.
Once removal of code that uses existing alpha is done, then duplicated code from /notifications/sms and the new endpoint can be merged. Job id is now avaiable in notificaiton but is not used yet.
This commit is contained in:
@@ -58,6 +58,11 @@ def fetch_client(client):
|
||||
"client": client,
|
||||
"secret": [current_app.config.get('ADMIN_CLIENT_SECRET')]
|
||||
}
|
||||
elif client == current_app.config.get('DELIVERY_CLIENT_USER_NAME'):
|
||||
return {
|
||||
"client": client,
|
||||
"secret": [current_app.config.get('DELIVERY_CLIENT_SECRET')]
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"client": client,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import uuid
|
||||
|
||||
from flask import (
|
||||
Blueprint,
|
||||
jsonify,
|
||||
@@ -49,3 +51,33 @@ def create_email_notification():
|
||||
notification['body'],
|
||||
notification['from_address'],
|
||||
notification['subject']))
|
||||
|
||||
|
||||
@notifications.route('/sms/service/<service_id>', methods=['POST'])
|
||||
def create_sms_for_service(service_id):
|
||||
|
||||
resp_json = request.get_json()
|
||||
|
||||
notification, errors = sms_template_notification_schema.load(resp_json)
|
||||
if errors:
|
||||
return jsonify(result="error", message=errors), 400
|
||||
|
||||
template_id = notification['template']
|
||||
job_id = notification['job']
|
||||
|
||||
# TODO: job/job_id is in notification and can used to update job status
|
||||
|
||||
# TODO: remove once beta is reading notifications from the queue
|
||||
template = templates_dao.get_model_templates(template_id)
|
||||
|
||||
if template.service.id != uuid.UUID(service_id):
|
||||
message = "Invalid template: id {} for service id: {}".format(template.id, service_id)
|
||||
return jsonify(result="error", message=message), 400
|
||||
|
||||
# Actual client is delivery app, but this is sent on behalf of service
|
||||
add_notification_to_queue(service_id, template_id, 'sms', notification)
|
||||
|
||||
# TODO: remove once beta is reading notifications from the queue
|
||||
content = template.content
|
||||
return jsonify(notify_alpha_client.send_sms(
|
||||
mobile_number=notification['to'], message=content)), 200
|
||||
|
||||
@@ -90,6 +90,7 @@ class SmsNotificationSchema(NotificationSchema):
|
||||
|
||||
class SmsTemplateNotificationSchema(SmsNotificationSchema):
|
||||
template = fields.Int(required=True)
|
||||
job = fields.String()
|
||||
|
||||
@validates('template')
|
||||
def validate_template(self, value):
|
||||
|
||||
Reference in New Issue
Block a user