Skip to content

Commit

Permalink
Adds protections to prevent hitting char limits in SaaS integrations (#…
Browse files Browse the repository at this point in the history
…2420)

* Adds protections to prevent hitting char limits in SaaS integrations
  • Loading branch information
mvilanova authored Aug 17, 2022
1 parent da23407 commit 44e612d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/dispatch/incident/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def send_welcome_ephemeral_message_to_participant(
message_kwargs = {
"name": incident.name,
"title": incident.title,
"description": incident.description,
"description": f"{incident.description[:500]}...",
"status": incident.status,
"type": incident.incident_type.name,
"type_description": incident.incident_type.description,
Expand Down Expand Up @@ -138,7 +138,7 @@ def send_welcome_email_to_participant(
message_kwargs = {
"name": incident.name,
"title": incident.title,
"description": incident.description,
"description": f"{incident.description[:500]}...",
"status": incident.status,
"type": incident.incident_type.name,
"type_description": incident.incident_type.description,
Expand Down Expand Up @@ -252,7 +252,7 @@ def send_incident_created_notifications(incident: Incident, db_session: SessionL
notification_kwargs = {
"name": incident.name,
"title": incident.title,
"description": incident.description,
"description": f"{incident.description[:500]}...",
"status": incident.status,
"type": incident.incident_type.name,
"type_description": incident.incident_type.description,
Expand Down Expand Up @@ -663,7 +663,7 @@ def send_incident_resources_ephemeral_message_to_participant(

message_kwargs = {
"title": incident.title,
"description": incident.description,
"description": f"{incident.description[:500]}...",
"commander_fullname": incident.commander.individual.name,
"commander_team": incident.commander.team,
"commander_weblink": incident.commander.individual.weblink,
Expand Down Expand Up @@ -766,8 +766,8 @@ def send_incident_closed_information_review_reminder(incident: Incident, db_sess
{
"name": incident.name,
"title": incident.title,
"description": f"{incident.description[:100]}",
"resolution": f"{incident.resolution[:100]}",
"description": f"{incident.description[:100]}...",
"resolution": f"{incident.resolution[:100]}...",
"type": incident.incident_type.name,
"priority": incident.incident_priority.name,
"dispatch_ui_incident_url": f"{DISPATCH_UI_URL}/{incident.project.organization.name}/incidents/{incident.name}",
Expand Down
4 changes: 4 additions & 0 deletions src/dispatch/messaging/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ def render_message_template(message_template: List[dict], **kwargs):
if d.get("text"):
d["text"] = Template(d["text"]).render(**kwargs)

# NOTE: we truncate the string to 2500 characters
# to prevent hitting limits on SaaS integrations (e.g. Slack)
d["text"] = d["text"] if len(d["text"]) <= 2500 else d["text"][:2500]

# render a new button array given the template
if d.get("buttons"):
for button in d["buttons"]:
Expand Down

0 comments on commit 44e612d

Please sign in to comment.