mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
remove v2
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
from flask import Blueprint
|
||||
|
||||
from app.v2.errors import register_errors
|
||||
|
||||
v2_notification_blueprint = Blueprint(
|
||||
"v2_notifications", __name__, url_prefix="/v2/notifications"
|
||||
)
|
||||
|
||||
register_errors(v2_notification_blueprint)
|
||||
@@ -1,66 +0,0 @@
|
||||
def create_post_sms_response_from_notification(
|
||||
notification_id,
|
||||
client_reference,
|
||||
template_id,
|
||||
template_version,
|
||||
service_id,
|
||||
content,
|
||||
from_number,
|
||||
url_root,
|
||||
):
|
||||
resp = __create_notification_response(
|
||||
notification_id,
|
||||
client_reference,
|
||||
template_id,
|
||||
template_version,
|
||||
service_id,
|
||||
url_root,
|
||||
)
|
||||
resp["content"] = {"from_number": from_number, "body": content}
|
||||
return resp
|
||||
|
||||
|
||||
def create_post_email_response_from_notification(
|
||||
notification_id,
|
||||
client_reference,
|
||||
template_id,
|
||||
template_version,
|
||||
service_id,
|
||||
content,
|
||||
subject,
|
||||
email_from,
|
||||
url_root,
|
||||
):
|
||||
resp = __create_notification_response(
|
||||
notification_id,
|
||||
client_reference,
|
||||
template_id,
|
||||
template_version,
|
||||
service_id,
|
||||
url_root,
|
||||
)
|
||||
resp["content"] = {"from_email": email_from, "body": content, "subject": subject}
|
||||
return resp
|
||||
|
||||
|
||||
def __create_notification_response(
|
||||
notification_id,
|
||||
client_reference,
|
||||
template_id,
|
||||
template_version,
|
||||
service_id,
|
||||
url_root,
|
||||
):
|
||||
return {
|
||||
"id": notification_id,
|
||||
"reference": client_reference,
|
||||
"uri": "{}v2/notifications/{}".format(url_root, str(notification_id)),
|
||||
"template": {
|
||||
"id": template_id,
|
||||
"version": template_version,
|
||||
"uri": "{}services/{}/templates/{}".format(
|
||||
url_root, str(service_id), str(template_id)
|
||||
),
|
||||
},
|
||||
"scheduled_for": None,
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
from flask import current_app, jsonify, request, url_for
|
||||
|
||||
from app import api_user, authenticated_service
|
||||
from app.aws.s3 import get_personalisation_from_s3
|
||||
from app.dao import notifications_dao
|
||||
from app.schema_validation import validate
|
||||
from app.v2.notifications import v2_notification_blueprint
|
||||
from app.v2.notifications.notification_schemas import (
|
||||
get_notifications_request,
|
||||
notification_by_id,
|
||||
)
|
||||
|
||||
|
||||
@v2_notification_blueprint.route("/<notification_id>", methods=["GET"])
|
||||
def get_notification_by_id(notification_id):
|
||||
_data = {"notification_id": notification_id}
|
||||
validate(_data, notification_by_id)
|
||||
notification = notifications_dao.get_notification_with_personalisation(
|
||||
authenticated_service.id, notification_id, key_type=None
|
||||
)
|
||||
notification.personalisation = get_personalisation_from_s3(
|
||||
notification.service_id,
|
||||
notification.job_id,
|
||||
notification.job_row_number,
|
||||
)
|
||||
return jsonify(notification.serialize()), 200
|
||||
|
||||
|
||||
@v2_notification_blueprint.route("", methods=["GET"])
|
||||
def get_notifications():
|
||||
_data = request.args.to_dict(flat=False)
|
||||
|
||||
# flat=False makes everything a list, but we only ever allow one value for "older_than"
|
||||
if "older_than" in _data:
|
||||
_data["older_than"] = _data["older_than"][0]
|
||||
|
||||
# and client reference
|
||||
if "reference" in _data:
|
||||
_data["reference"] = _data["reference"][0]
|
||||
|
||||
if "include_jobs" in _data:
|
||||
_data["include_jobs"] = _data["include_jobs"][0]
|
||||
|
||||
data = validate(_data, get_notifications_request)
|
||||
|
||||
paginated_notifications = notifications_dao.get_notifications_for_service(
|
||||
str(authenticated_service.id),
|
||||
filter_dict=data,
|
||||
key_type=api_user.key_type,
|
||||
personalisation=True,
|
||||
older_than=data.get("older_than"),
|
||||
client_reference=data.get("reference"),
|
||||
page_size=current_app.config.get("API_PAGE_SIZE"),
|
||||
include_jobs=data.get("include_jobs"),
|
||||
count_pages=False,
|
||||
)
|
||||
|
||||
for notification in paginated_notifications.items:
|
||||
if notification.job_id is not None:
|
||||
notification.personalisation = get_personalisation_from_s3(
|
||||
notification.service_id,
|
||||
notification.job_id,
|
||||
notification.job_row_number,
|
||||
)
|
||||
|
||||
def _build_links(notifications):
|
||||
_links = {
|
||||
"current": url_for(".get_notifications", _external=True, **data),
|
||||
}
|
||||
|
||||
if len(notifications):
|
||||
next_query_params = dict(data, older_than=notifications[-1].id)
|
||||
_links["next"] = url_for(
|
||||
".get_notifications", _external=True, **next_query_params
|
||||
)
|
||||
|
||||
return _links
|
||||
|
||||
return (
|
||||
jsonify(
|
||||
notifications=[
|
||||
notification.serialize()
|
||||
for notification in paginated_notifications.items
|
||||
],
|
||||
links=_build_links(paginated_notifications.items),
|
||||
),
|
||||
200,
|
||||
)
|
||||
@@ -1,211 +0,0 @@
|
||||
from app.enums import NotificationStatus, TemplateType
|
||||
from app.schema_validation.definitions import personalisation, uuid
|
||||
|
||||
template = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "template schema",
|
||||
"type": "object",
|
||||
"title": "notification content",
|
||||
"properties": {
|
||||
"id": uuid,
|
||||
"version": {"type": "integer"},
|
||||
"uri": {"type": "string", "format": "uri"},
|
||||
},
|
||||
"required": ["id", "version", "uri"],
|
||||
}
|
||||
|
||||
notification_by_id = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "GET notification response schema",
|
||||
"type": "object",
|
||||
"title": "response v2/notification",
|
||||
"properties": {"notification_id": uuid},
|
||||
"required": ["notification_id"],
|
||||
}
|
||||
|
||||
|
||||
get_notification_response = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "GET notification response schema",
|
||||
"type": "object",
|
||||
"title": "response v2/notification",
|
||||
"properties": {
|
||||
"id": uuid,
|
||||
"reference": {"type": ["string", "null"]},
|
||||
"email_address": {"type": ["string", "null"]},
|
||||
"phone_number": {"type": ["string", "null"]},
|
||||
"line_1": {"type": ["string", "null"]},
|
||||
"line_2": {"type": ["string", "null"]},
|
||||
"line_3": {"type": ["string", "null"]},
|
||||
"line_4": {"type": ["string", "null"]},
|
||||
"line_5": {"type": ["string", "null"]},
|
||||
"line_6": {"type": ["string", "null"]},
|
||||
"postcode": {"type": ["string", "null"]},
|
||||
"type": {"enum": list(TemplateType)},
|
||||
"status": {"type": "string"},
|
||||
"template": template,
|
||||
"body": {"type": "string"},
|
||||
"subject": {"type": ["string", "null"]},
|
||||
"created_at": {"type": "string"},
|
||||
"sent_at": {"type": ["string", "null"]},
|
||||
"completed_at": {"type": ["string", "null"]},
|
||||
"scheduled_for": {"type": ["string", "null"]},
|
||||
},
|
||||
"required": [
|
||||
# technically, all keys are required since we always have all of them
|
||||
"id",
|
||||
"reference",
|
||||
"email_address",
|
||||
"phone_number",
|
||||
"line_1",
|
||||
"line_2",
|
||||
"line_3",
|
||||
"line_4",
|
||||
"line_5",
|
||||
"line_6",
|
||||
"postcode",
|
||||
"type",
|
||||
"status",
|
||||
"template",
|
||||
"body",
|
||||
"created_at",
|
||||
"sent_at",
|
||||
"completed_at",
|
||||
],
|
||||
}
|
||||
|
||||
get_notifications_request = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "schema for query parameters allowed when getting list of notifications",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"reference": {"type": "string"},
|
||||
"status": {
|
||||
"type": "array",
|
||||
"items": {"enum": list(NotificationStatus)},
|
||||
},
|
||||
"template_type": {
|
||||
"type": "array",
|
||||
"items": {"enum": list(TemplateType)},
|
||||
},
|
||||
"include_jobs": {"enum": ["true", "True"]},
|
||||
"older_than": uuid,
|
||||
},
|
||||
"additionalProperties": False,
|
||||
}
|
||||
|
||||
get_notifications_response = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "GET list of notifications response schema",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"notifications": {
|
||||
"type": "array",
|
||||
"items": {"type": "object", "$ref": "#/definitions/notification"},
|
||||
},
|
||||
"links": {
|
||||
"type": "object",
|
||||
"properties": {"current": {"type": "string"}, "next": {"type": "string"}},
|
||||
"additionalProperties": False,
|
||||
"required": ["current"],
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["notifications", "links"],
|
||||
"definitions": {"notification": get_notification_response},
|
||||
}
|
||||
|
||||
post_sms_request = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "POST sms notification schema",
|
||||
"type": "object",
|
||||
"title": "POST v2/notifications/sms",
|
||||
"properties": {
|
||||
"reference": {"type": "string"},
|
||||
"phone_number": {"type": "string", "format": "phone_number"},
|
||||
"template_id": uuid,
|
||||
"personalisation": personalisation,
|
||||
"scheduled_for": {
|
||||
"type": ["string", "null"],
|
||||
"format": "datetime_within_next_day",
|
||||
},
|
||||
"sms_sender_id": uuid,
|
||||
},
|
||||
"required": ["phone_number", "template_id"],
|
||||
"additionalProperties": False,
|
||||
}
|
||||
|
||||
sms_content = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "content schema for SMS notification response schema",
|
||||
"type": "object",
|
||||
"title": "notification content",
|
||||
"properties": {"body": {"type": "string"}, "from_number": {"type": "string"}},
|
||||
"required": ["body", "from_number"],
|
||||
}
|
||||
|
||||
post_sms_response = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "POST sms notification response schema",
|
||||
"type": "object",
|
||||
"title": "response v2/notifications/sms",
|
||||
"properties": {
|
||||
"id": uuid,
|
||||
"reference": {"type": ["string", "null"]},
|
||||
"content": sms_content,
|
||||
"uri": {"type": "string", "format": "uri"},
|
||||
"template": template,
|
||||
"scheduled_for": {"type": ["string", "null"]},
|
||||
},
|
||||
"required": ["id", "content", "uri", "template"],
|
||||
}
|
||||
|
||||
|
||||
post_email_request = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "POST email notification schema",
|
||||
"type": "object",
|
||||
"title": "POST v2/notifications/email",
|
||||
"properties": {
|
||||
"reference": {"type": "string"},
|
||||
"email_address": {"type": "string", "format": "email_address"},
|
||||
"template_id": uuid,
|
||||
"personalisation": personalisation,
|
||||
"scheduled_for": {
|
||||
"type": ["string", "null"],
|
||||
"format": "datetime_within_next_day",
|
||||
},
|
||||
"email_reply_to_id": uuid,
|
||||
},
|
||||
"required": ["email_address", "template_id"],
|
||||
"additionalProperties": False,
|
||||
}
|
||||
|
||||
email_content = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "Email content for POST email notification",
|
||||
"type": "object",
|
||||
"title": "notification email content",
|
||||
"properties": {
|
||||
"from_email": {"type": "string", "format": "email_address"},
|
||||
"body": {"type": "string"},
|
||||
"subject": {"type": "string"},
|
||||
},
|
||||
"required": ["body", "from_email", "subject"],
|
||||
}
|
||||
|
||||
post_email_response = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "POST email notification response schema",
|
||||
"type": "object",
|
||||
"title": "response v2/notifications/email",
|
||||
"properties": {
|
||||
"id": uuid,
|
||||
"reference": {"type": ["string", "null"]},
|
||||
"content": email_content,
|
||||
"uri": {"type": "string", "format": "uri"},
|
||||
"template": template,
|
||||
"scheduled_for": {"type": ["string", "null"]},
|
||||
},
|
||||
"required": ["id", "content", "uri", "template"],
|
||||
}
|
||||
@@ -1,338 +0,0 @@
|
||||
import functools
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
import botocore
|
||||
from flask import abort, current_app, jsonify, request
|
||||
|
||||
from app import api_user, authenticated_service, document_download_client, encryption
|
||||
from app.celery.tasks import save_api_email, save_api_sms
|
||||
from app.clients.document_download import DocumentDownloadError
|
||||
from app.config import QueueNames
|
||||
from app.enums import KeyType, NotificationStatus, NotificationType, TemplateProcessType
|
||||
from app.models import Notification
|
||||
from app.notifications.process_notifications import (
|
||||
persist_notification,
|
||||
send_notification_to_queue_detached,
|
||||
simulated_recipient,
|
||||
)
|
||||
from app.notifications.validators import (
|
||||
check_if_service_can_send_files_by_email,
|
||||
check_is_message_too_long,
|
||||
check_rate_limiting,
|
||||
check_service_email_reply_to_id,
|
||||
check_service_has_permission,
|
||||
check_service_sms_sender_id,
|
||||
validate_and_format_recipient,
|
||||
validate_template,
|
||||
)
|
||||
from app.schema_validation import validate
|
||||
from app.utils import DATETIME_FORMAT
|
||||
from app.v2.errors import BadRequestError
|
||||
from app.v2.notifications import v2_notification_blueprint
|
||||
from app.v2.notifications.create_response import (
|
||||
create_post_email_response_from_notification,
|
||||
create_post_sms_response_from_notification,
|
||||
)
|
||||
from app.v2.notifications.notification_schemas import (
|
||||
post_email_request,
|
||||
post_sms_request,
|
||||
)
|
||||
from app.v2.utils import get_valid_json
|
||||
from notifications_utils.recipients import try_validate_and_format_phone_number
|
||||
|
||||
|
||||
@v2_notification_blueprint.route("/<notification_type>", methods=["POST"])
|
||||
def post_notification(notification_type):
|
||||
request_json = get_valid_json()
|
||||
|
||||
if notification_type == NotificationType.EMAIL:
|
||||
form = validate(request_json, post_email_request)
|
||||
elif notification_type == NotificationType.SMS:
|
||||
form = validate(request_json, post_sms_request)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
check_service_has_permission(notification_type, authenticated_service.permissions)
|
||||
|
||||
check_rate_limiting(authenticated_service, api_user)
|
||||
|
||||
template, template_with_content = validate_template(
|
||||
form["template_id"],
|
||||
form.get("personalisation", {}),
|
||||
authenticated_service,
|
||||
notification_type,
|
||||
check_char_count=False,
|
||||
)
|
||||
|
||||
reply_to = get_reply_to_text(notification_type, form, template)
|
||||
|
||||
notification = process_sms_or_email_notification(
|
||||
form=form,
|
||||
notification_type=notification_type,
|
||||
template=template,
|
||||
template_with_content=template_with_content,
|
||||
template_process_type=template.process_type,
|
||||
service=authenticated_service,
|
||||
reply_to_text=reply_to,
|
||||
)
|
||||
|
||||
return jsonify(notification), 201
|
||||
|
||||
|
||||
def process_sms_or_email_notification(
|
||||
*,
|
||||
form,
|
||||
notification_type,
|
||||
template,
|
||||
template_with_content,
|
||||
template_process_type,
|
||||
service,
|
||||
reply_to_text=None,
|
||||
):
|
||||
notification_id = uuid.uuid4()
|
||||
form_send_to = (
|
||||
form["email_address"]
|
||||
if notification_type == NotificationType.EMAIL
|
||||
else form["phone_number"]
|
||||
)
|
||||
|
||||
send_to = validate_and_format_recipient(
|
||||
send_to=form_send_to,
|
||||
key_type=api_user.key_type,
|
||||
service=service,
|
||||
notification_type=notification_type,
|
||||
)
|
||||
|
||||
# Do not persist or send notification to the queue if it is a simulated recipient
|
||||
simulated = simulated_recipient(send_to, notification_type)
|
||||
|
||||
personalisation, document_download_count = process_document_uploads(
|
||||
form.get("personalisation"), service, simulated=simulated
|
||||
)
|
||||
if document_download_count:
|
||||
# We changed personalisation which means we need to update the content
|
||||
template_with_content.values = personalisation
|
||||
|
||||
# validate content length after url is replaced in personalisation.
|
||||
check_is_message_too_long(template_with_content)
|
||||
|
||||
resp = create_response_for_post_notification(
|
||||
notification_id=notification_id,
|
||||
client_reference=form.get("reference", None),
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
service_id=service.id,
|
||||
notification_type=notification_type,
|
||||
reply_to=reply_to_text,
|
||||
template_with_content=template_with_content,
|
||||
)
|
||||
|
||||
if (
|
||||
service.high_volume
|
||||
and api_user.key_type == KeyType.NORMAL
|
||||
and notification_type in {NotificationType.EMAIL, NotificationType.SMS}
|
||||
):
|
||||
# Put service with high volumes of notifications onto a queue
|
||||
# To take the pressure off the db for API requests put the notification for our high volume service onto a queue
|
||||
# the task will then save the notification, then call send_notification_to_queue.
|
||||
# NOTE: The high volume service should be aware that the notification is not immediately
|
||||
# available by a GET request, it is recommend they use callbacks to keep track of status updates.
|
||||
try:
|
||||
save_email_or_sms_to_queue(
|
||||
form=form,
|
||||
notification_id=str(notification_id),
|
||||
notification_type=notification_type,
|
||||
api_key=api_user,
|
||||
template=template,
|
||||
service_id=service.id,
|
||||
personalisation=personalisation,
|
||||
document_download_count=document_download_count,
|
||||
reply_to_text=reply_to_text,
|
||||
)
|
||||
return resp
|
||||
except (botocore.exceptions.ClientError, botocore.parsers.ResponseParserError):
|
||||
# If SQS cannot put the task on the queue, it's probably because the notification body was too long and it
|
||||
# went over SQS's 256kb message limit. If the body is very large, it may exceed the HTTP max content length;
|
||||
# the exception we get here isn't handled correctly by botocore - we get a ResponseParserError instead.
|
||||
# Hopefully this is no longer an issue with Redis as celery's backing store
|
||||
current_app.logger.info(
|
||||
f"Notification {notification_id} failed to save to high volume queue. Using normal flow instead"
|
||||
)
|
||||
|
||||
persist_notification(
|
||||
notification_id=notification_id,
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
recipient=form_send_to,
|
||||
service=service,
|
||||
personalisation=personalisation,
|
||||
notification_type=notification_type,
|
||||
api_key_id=api_user.id,
|
||||
key_type=api_user.key_type,
|
||||
client_reference=form.get("reference", None),
|
||||
simulated=simulated,
|
||||
reply_to_text=reply_to_text,
|
||||
document_download_count=document_download_count,
|
||||
)
|
||||
|
||||
if not simulated:
|
||||
queue_name = (
|
||||
QueueNames.PRIORITY
|
||||
if template_process_type == TemplateProcessType.PRIORITY
|
||||
else None
|
||||
)
|
||||
send_notification_to_queue_detached(
|
||||
key_type=api_user.key_type,
|
||||
notification_type=notification_type,
|
||||
notification_id=notification_id,
|
||||
queue=queue_name,
|
||||
)
|
||||
else:
|
||||
current_app.logger.debug(
|
||||
"POST simulated notification for id: {}".format(notification_id)
|
||||
)
|
||||
|
||||
return resp
|
||||
|
||||
|
||||
def save_email_or_sms_to_queue(
|
||||
*,
|
||||
notification_id,
|
||||
form,
|
||||
notification_type,
|
||||
api_key,
|
||||
template,
|
||||
service_id,
|
||||
personalisation,
|
||||
document_download_count,
|
||||
reply_to_text=None,
|
||||
):
|
||||
data = {
|
||||
"id": notification_id,
|
||||
"template_id": str(template.id),
|
||||
"template_version": template.version,
|
||||
"to": (
|
||||
form["email_address"]
|
||||
if notification_type == NotificationType.EMAIL
|
||||
else form["phone_number"]
|
||||
),
|
||||
"service_id": str(service_id),
|
||||
"personalisation": personalisation,
|
||||
"notification_type": notification_type,
|
||||
"api_key_id": str(api_key.id),
|
||||
"key_type": api_key.key_type,
|
||||
"client_reference": form.get("reference", None),
|
||||
"reply_to_text": reply_to_text,
|
||||
"document_download_count": document_download_count,
|
||||
"status": NotificationStatus.CREATED,
|
||||
"created_at": datetime.utcnow().strftime(DATETIME_FORMAT),
|
||||
}
|
||||
encrypted = encryption.encrypt(data)
|
||||
|
||||
if notification_type == NotificationType.EMAIL:
|
||||
save_api_email.apply_async([encrypted], queue=QueueNames.SAVE_API_EMAIL)
|
||||
elif notification_type == NotificationType.SMS:
|
||||
save_api_sms.apply_async([encrypted], queue=QueueNames.SAVE_API_SMS)
|
||||
|
||||
return Notification(**data)
|
||||
|
||||
|
||||
def process_document_uploads(personalisation_data, service, simulated=False):
|
||||
"""
|
||||
Returns modified personalisation dict and a count of document uploads. If there are no document uploads, returns
|
||||
a count of `None` rather than `0`.
|
||||
"""
|
||||
file_keys = [
|
||||
k
|
||||
for k, v in (personalisation_data or {}).items()
|
||||
if isinstance(v, dict) and "file" in v
|
||||
]
|
||||
if not file_keys:
|
||||
return personalisation_data, None
|
||||
|
||||
personalisation_data = personalisation_data.copy()
|
||||
|
||||
check_if_service_can_send_files_by_email(
|
||||
service_contact_link=authenticated_service.contact_link,
|
||||
service_id=authenticated_service.id,
|
||||
)
|
||||
|
||||
for key in file_keys:
|
||||
if simulated:
|
||||
personalisation_data[key] = (
|
||||
document_download_client.get_upload_url(service.id) + "/test-document"
|
||||
)
|
||||
else:
|
||||
try:
|
||||
personalisation_data[key] = document_download_client.upload_document(
|
||||
service.id,
|
||||
personalisation_data[key]["file"],
|
||||
personalisation_data[key].get("is_csv"),
|
||||
)
|
||||
except DocumentDownloadError as e:
|
||||
raise BadRequestError(message=e.message, status_code=e.status_code)
|
||||
|
||||
return personalisation_data, len(file_keys)
|
||||
|
||||
|
||||
def get_reply_to_text(notification_type, form, template):
|
||||
reply_to = None
|
||||
if notification_type == NotificationType.EMAIL:
|
||||
service_email_reply_to_id = form.get("email_reply_to_id", None)
|
||||
reply_to = (
|
||||
check_service_email_reply_to_id(
|
||||
str(authenticated_service.id),
|
||||
service_email_reply_to_id,
|
||||
notification_type,
|
||||
)
|
||||
or template.reply_to_text
|
||||
)
|
||||
|
||||
elif notification_type == NotificationType.SMS:
|
||||
service_sms_sender_id = form.get("sms_sender_id", None)
|
||||
sms_sender_id = check_service_sms_sender_id(
|
||||
str(authenticated_service.id), service_sms_sender_id, notification_type
|
||||
)
|
||||
if sms_sender_id:
|
||||
reply_to = try_validate_and_format_phone_number(sms_sender_id)
|
||||
else:
|
||||
reply_to = template.reply_to_text
|
||||
|
||||
return reply_to
|
||||
|
||||
|
||||
def create_response_for_post_notification(
|
||||
notification_id,
|
||||
client_reference,
|
||||
template_id,
|
||||
template_version,
|
||||
service_id,
|
||||
notification_type,
|
||||
reply_to,
|
||||
template_with_content,
|
||||
):
|
||||
if notification_type == NotificationType.SMS:
|
||||
create_resp_partial = functools.partial(
|
||||
create_post_sms_response_from_notification,
|
||||
from_number=reply_to,
|
||||
)
|
||||
elif notification_type == NotificationType.EMAIL:
|
||||
create_resp_partial = functools.partial(
|
||||
create_post_email_response_from_notification,
|
||||
subject=template_with_content.subject,
|
||||
email_from="{}@{}".format(
|
||||
authenticated_service.email_from,
|
||||
current_app.config["NOTIFY_EMAIL_DOMAIN"],
|
||||
),
|
||||
)
|
||||
resp = create_resp_partial(
|
||||
notification_id,
|
||||
client_reference,
|
||||
template_id,
|
||||
template_version,
|
||||
service_id,
|
||||
url_root=request.url_root,
|
||||
content=template_with_content.content_with_placeholders_filled_in,
|
||||
)
|
||||
return resp
|
||||
Reference in New Issue
Block a user