mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
Add page explaining how to send template using API
Would like to test something like this and see how well it works. Intention of having this page is so: - template IDs are discoverable (https://www.pivotaltracker.com/story/show/115404593) - it’s obvious there’s an ‘automated’ way to send messages, as well as the CSV way (we’ve seen people oblivious to this in research)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import csv
|
||||
import io
|
||||
import json
|
||||
import uuid
|
||||
from contextlib import suppress
|
||||
|
||||
@@ -197,6 +198,29 @@ def send_message_to_self(service_id, template_id):
|
||||
upload_id=upload_id))
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/send/<template_id>/from-api", methods=['GET'])
|
||||
@login_required
|
||||
@user_has_permissions('manage_api_keys', 'access_developer_docs')
|
||||
def send_from_api(service_id, template_id):
|
||||
template = Template(
|
||||
templates_dao.get_service_template_or_404(service_id, template_id)['data']
|
||||
)
|
||||
payload = {
|
||||
"to": current_user.mobile_number,
|
||||
"template": template.id,
|
||||
"personalisation": {
|
||||
placeholder: "{} 1".format(placeholder) for placeholder in template.placeholders
|
||||
}
|
||||
}
|
||||
return render_template(
|
||||
'views/send-from-api.html',
|
||||
template=template,
|
||||
payload=json.dumps(payload, indent=4),
|
||||
api_host=current_app.config['API_HOST_NAME'],
|
||||
service_id=service_id
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/check/<upload_id>", methods=['GET'])
|
||||
@login_required
|
||||
@user_has_permissions('send_texts', 'send_emails', 'send_letters')
|
||||
|
||||
Reference in New Issue
Block a user