Skip to content

Commit 1d7dbdc

Browse files
devin-ai-integration[bot]Michael Myaskovsky
andcommitted
Fix edge cases: handle single oversized body item, use valid TextBlock markdown for italic
Co-Authored-By: Michael Myaskovsky <michael@elementary-data.com>
1 parent f7b1130 commit 1d7dbdc

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

elementary/messages/messaging_integrations/teams_webhook.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,27 @@ def _build_payload(card: dict) -> dict:
5757
def _truncation_notice_item() -> Dict[str, Any]:
5858
return {
5959
"type": "TextBlock",
60-
"text": "... Content truncated due to message size limits. "
61-
"View full details in Elementary Cloud.",
60+
"text": "_... Content truncated due to message size limits. "
61+
"View full details in Elementary Cloud._",
6262
"wrap": True,
6363
"isSubtle": True,
64-
"italic": True,
64+
}
65+
66+
67+
def _minimal_card(card: dict) -> dict:
68+
"""Return a minimal card with just a truncation notice when even a single
69+
body item is too large."""
70+
return {
71+
**card,
72+
"body": [
73+
{
74+
"type": "TextBlock",
75+
"text": "Alert content too large to display in Teams. "
76+
"View full details in Elementary Cloud.",
77+
"wrap": True,
78+
"weight": "bolder",
79+
}
80+
],
6581
}
6682

6783

@@ -79,7 +95,12 @@ def _truncate_card(card: dict) -> dict:
7995
break
8096
body.pop() # remove the last body item
8197

82-
return {**card, "body": body + [_truncation_notice_item()]}
98+
truncated = {**card, "body": body + [_truncation_notice_item()]}
99+
# If even a single body item plus the notice is too large, fall back to
100+
# a minimal card.
101+
if len(json.dumps(_build_payload(truncated))) > TEAMS_PAYLOAD_SIZE_LIMIT:
102+
return _minimal_card(card)
103+
return truncated
83104

84105

85106
def send_adaptive_card(webhook_url: str, card: dict) -> requests.Response:

0 commit comments

Comments
 (0)