mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 16:38:59 -04:00
> Once an inbound message has been received, there should be a way to > see the other messages in the system from the same service to the same > number. Both in and outbound. Nice inbox/whatsapp stylee view or some > such. This way the context of the reply is understood. > > Initially will only see the outbound template, not the actual message, > but we’re going to change this for the rest (soon), so that you can > always see the full message for all outbound.
56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
from flask import (
|
|
render_template,
|
|
url_for,
|
|
)
|
|
from flask_login import login_required
|
|
from notifications_utils.recipients import format_phone_number_human_readable
|
|
from notifications_utils.template import SMSPreviewTemplate
|
|
from app.main import main
|
|
from app.utils import user_has_permissions
|
|
from app import notification_api_client, service_api_client
|
|
|
|
|
|
@main.route("/services/<service_id>/conversation/<notification_id>")
|
|
@login_required
|
|
@user_has_permissions('view_activity', admin_override=True)
|
|
def conversation(service_id, notification_id):
|
|
|
|
user_number = get_user_number(service_id, notification_id)
|
|
|
|
return render_template(
|
|
'views/conversations/conversation.html',
|
|
conversation=get_sms_thread(service_id, user_number=user_number),
|
|
user_number=user_number,
|
|
)
|
|
|
|
|
|
def get_user_number(service_id, notification_id):
|
|
try:
|
|
user_number = service_api_client.get_inbound_sms_by_id(service_id, notification_id)['user_number']
|
|
except Exception:
|
|
user_number = notification_api_client.get_notification(service_id, notification_id)['to']
|
|
return format_phone_number_human_readable(user_number)
|
|
|
|
|
|
def get_sms_thread(service_id, user_number):
|
|
return [
|
|
{
|
|
'inbound': ('notify_number' in notification),
|
|
'content': SMSPreviewTemplate(
|
|
{
|
|
'content': notification.get('content') or notification['template']['content']
|
|
}
|
|
),
|
|
'created_at': notification['created_at'],
|
|
'status': notification.get('status'),
|
|
'id': notification['id'],
|
|
}
|
|
for notification in sorted(
|
|
(
|
|
notification_api_client.get_notifications_for_service(service_id, to=user_number)['notifications'] +
|
|
service_api_client.get_inbound_sms(service_id, user_number=user_number)
|
|
),
|
|
key=lambda notification: notification['created_at'],
|
|
)
|
|
]
|