mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-12 09:58:50 -04:00
Add a page to pick a template to reply with
If your service is receiving inbound messages, you might want to reply to them. Without an API integration, the only way to do this is by doing the send one off flow. But currently there is no direct link from the page which shows the inbound messages. So this commit: - adds a link to a new page… - …which shows the available (ie only text message) templates with which you can reply
This commit is contained in:
@@ -7,6 +7,7 @@ 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.main.forms import SearchTemplatesForm
|
||||
from app.utils import user_has_permissions
|
||||
from app import notification_api_client, service_api_client
|
||||
from notifications_python_client.errors import HTTPError
|
||||
@@ -24,6 +25,7 @@ def conversation(service_id, notification_id):
|
||||
user_number=user_number,
|
||||
partials=get_conversation_partials(service_id, user_number),
|
||||
updates_url=url_for('.conversation_updates', service_id=service_id, notification_id=notification_id),
|
||||
notification_id=notification_id,
|
||||
)
|
||||
|
||||
|
||||
@@ -38,6 +40,29 @@ def conversation_updates(service_id, notification_id):
|
||||
))
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/conversation/<notification_id>/reply-with")
|
||||
@login_required
|
||||
@user_has_permissions('send_texts', admin_override=True)
|
||||
def conversation_reply(
|
||||
service_id,
|
||||
notification_id,
|
||||
):
|
||||
|
||||
templates = [
|
||||
template
|
||||
for template in service_api_client.get_service_templates(service_id)['data']
|
||||
if template['template_type'] == 'sms'
|
||||
]
|
||||
|
||||
return render_template(
|
||||
'views/templates/choose-reply.html',
|
||||
templates=templates,
|
||||
show_search_box=(len(templates) > 7),
|
||||
template_type='sms',
|
||||
search_form=SearchTemplatesForm(),
|
||||
)
|
||||
|
||||
|
||||
def get_conversation_partials(service_id, user_number):
|
||||
|
||||
return {
|
||||
|
||||
@@ -22,6 +22,12 @@
|
||||
'messages',
|
||||
) }}
|
||||
|
||||
{% if current_user.has_permissions(['send_texts'], admin_override=True) %}
|
||||
<p>
|
||||
<a href="{{ url_for('.conversation_reply', service_id=current_service.id, notification_id=notification_id) }}">Send a text message to this phone number</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
56
app/templates/views/templates/choose-reply.html
Normal file
56
app/templates/views/templates/choose-reply.html
Normal file
@@ -0,0 +1,56 @@
|
||||
{% from "components/pill.html" import pill %}
|
||||
{% from "components/message-count-label.html" import message_count_label %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
|
||||
{% extends "withnav_template.html" %}
|
||||
|
||||
{% block service_page_title %}
|
||||
Choose a template
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
<h1 class="heading-large">Choose a template</h1>
|
||||
|
||||
{% if not templates %}
|
||||
|
||||
{% if current_user.has_permissions(permissions=['manage_templates'], any_=True) %}
|
||||
<p class="bottom-gutter">
|
||||
You need a template before you can send text messages.
|
||||
</p>
|
||||
<a href="{{ url_for('.add_template_by_type', service_id=current_service.id) }}" class="button">Add a new template</a>
|
||||
{% else %}
|
||||
<p>
|
||||
You need to ask your service manager to add templates before you
|
||||
can send text messages.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
|
||||
{% if show_search_box %}
|
||||
<div data-module="autofocus">
|
||||
<div class="live-search" data-module="live-search" data-targets="#template-list .column-whole">
|
||||
{{ textbox(
|
||||
search_form.search,
|
||||
width='1-1'
|
||||
) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<nav class="grid-row" id=template-list>
|
||||
{% for template in templates %}
|
||||
<div class="column-whole">
|
||||
<h2 class="message-name">
|
||||
<a href="{{ url_for('.view_template', service_id=current_service.id, template_id=template.id) }}">{{ template.name }}</a>
|
||||
</h2>
|
||||
<p class="message-type">
|
||||
{{ message_count_label(1, template.template_type, suffix='')|capitalize }} template
|
||||
</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</nav>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
@@ -214,3 +214,51 @@ def test_view_conversation_with_empty_inbound(
|
||||
|
||||
messages = page.select('.sms-message-wrapper')
|
||||
assert len(messages) == 1
|
||||
|
||||
|
||||
def test_conversation_links_to_reply(
|
||||
client_request,
|
||||
fake_uuid,
|
||||
mock_get_notification,
|
||||
mock_get_notifications,
|
||||
mock_get_inbound_sms,
|
||||
):
|
||||
page = client_request.get(
|
||||
'main.conversation',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
notification_id=fake_uuid,
|
||||
)
|
||||
|
||||
assert page.select('main p')[-1].select_one('a')['href'] == (
|
||||
url_for(
|
||||
'.conversation_reply',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
notification_id=fake_uuid,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_conversation_reply_shows_templates(
|
||||
client_request,
|
||||
fake_uuid,
|
||||
mock_get_service_templates,
|
||||
):
|
||||
page = client_request.get(
|
||||
'main.conversation_reply',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
notification_id=fake_uuid,
|
||||
)
|
||||
|
||||
for index, expected in enumerate([
|
||||
'sms_template_one',
|
||||
'sms_template_two',
|
||||
]):
|
||||
link = page.select('.message-name')[index]
|
||||
assert normalize_spaces(link.text) == expected
|
||||
assert link.select_one('a')['href'].startswith(
|
||||
url_for(
|
||||
'main.view_template',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id='',
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user