Skip to content

Commit a715f67

Browse files
devin-ai-integration[bot]Michael Myaskovsky
andcommitted
Fix Teams 413 error: add charset=utf-8 to Content-Type header and retry on 413
Co-Authored-By: Michael Myaskovsky <michael@elementary-data.com>
1 parent ed170b7 commit a715f67

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

elementary/messages/messaging_integrations/teams_webhook.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,26 @@ def send_adaptive_card(webhook_url: str, card: dict) -> requests.Response:
107107
response = requests.post(
108108
webhook_url,
109109
json=payload,
110-
headers={"Content-Type": "application/json"},
110+
headers={"Content-Type": "application/json; charset=utf-8"},
111111
)
112112
response.raise_for_status()
113+
if (
114+
response.status_code == HTTPStatus.OK
115+
and len(response.text) > 1
116+
and "413" in response.text
117+
):
118+
logger.warning(
119+
"Teams webhook returned 413 in response body (payload size issue), "
120+
"retrying with minimal card"
121+
)
122+
minimal = _minimal_card(card)
123+
payload = _build_payload(minimal)
124+
response = requests.post(
125+
webhook_url,
126+
json=payload,
127+
headers={"Content-Type": "application/json; charset=utf-8"},
128+
)
129+
response.raise_for_status()
113130
if response.status_code == HTTPStatus.ACCEPTED:
114131
logger.debug(
115132
f"Got {HTTPStatus.ACCEPTED} response from Teams webhook, assuming success"

0 commit comments

Comments
 (0)