File tree Expand file tree Collapse file tree
elementary/messages/messaging_integrations Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,11 +57,27 @@ def _build_payload(card: dict) -> dict:
5757def _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
85106def send_adaptive_card (webhook_url : str , card : dict ) -> requests .Response :
You can’t perform that action at this time.
0 commit comments