mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Get the sms sender from the notificaiton_sms_sender mapping table if that does not exist get the default sms sender to pass on to the sms provider.
This commit is contained in:
@@ -44,7 +44,9 @@ from app.models import (
|
||||
NOTIFICATION_TEMPORARY_FAILURE,
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_SENT,
|
||||
NotificationSmsSender)
|
||||
NotificationSmsSender,
|
||||
ServiceSmsSender
|
||||
)
|
||||
|
||||
from app.dao.dao_utils import transactional
|
||||
from app.statsd_decorators import statsd
|
||||
@@ -659,3 +661,14 @@ def dao_create_notification_sms_sender_mapping(notification_id, sms_sender_id):
|
||||
service_sms_sender_id=sms_sender_id
|
||||
)
|
||||
db.session.add(notification_to_sms_sender)
|
||||
|
||||
|
||||
def dao_get_notification_sms_sender_mapping(notification_id):
|
||||
sms_sender = ServiceSmsSender.query.join(
|
||||
NotificationSmsSender
|
||||
).filter(
|
||||
NotificationSmsSender.notification_id == notification_id
|
||||
).first()
|
||||
|
||||
if sms_sender:
|
||||
return sms_sender.sms_sender
|
||||
|
||||
@@ -11,8 +11,8 @@ from notifications_utils.template import HTMLEmailTemplate, PlainTextEmailTempla
|
||||
from app import clients, statsd_client, create_uuid
|
||||
from app.dao.notifications_dao import (
|
||||
dao_update_notification,
|
||||
dao_get_notification_email_reply_for_notification
|
||||
)
|
||||
dao_get_notification_email_reply_for_notification,
|
||||
dao_get_notification_sms_sender_mapping)
|
||||
from app.dao.provider_details_dao import (
|
||||
get_provider_details_by_notification_type,
|
||||
dao_toggle_sms_provider
|
||||
@@ -69,11 +69,15 @@ def send_sms_to_provider(notification):
|
||||
raise
|
||||
else:
|
||||
try:
|
||||
sms_sender = dao_get_notification_sms_sender_mapping(notification.id)
|
||||
if not sms_sender:
|
||||
sms_sender = service.get_default_sms_sender()
|
||||
|
||||
provider.send_sms(
|
||||
to=validate_and_format_phone_number(notification.to, international=notification.international),
|
||||
content=str(template),
|
||||
reference=str(notification.id),
|
||||
sender=service.get_default_sms_sender()
|
||||
sender=sms_sender
|
||||
)
|
||||
except Exception as e:
|
||||
dao_toggle_sms_provider(provider.name)
|
||||
|
||||
Reference in New Issue
Block a user