Skip to content

Commit 947f518

Browse files
author
Frank Tubbing
committed
Implemented feedback of Elazar
1 parent 9a4b058 commit 947f518

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

elementary/messages/formats/adaptive_cards.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def format_fact_list_block(block: FactListBlock) -> Dict[str, Any]:
131131
}
132132

133133

134-
def format_table_block(block: TableBlock) -> dict:
134+
def format_table_block(block: TableBlock) -> Dict[str, Any]:
135135
return {
136136
"type": "Table",
137137
"columns": [{"width": 1} for _ in block.headers],

elementary/messages/messaging_integrations/teams_webhook.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def send_adaptive_card(webhook_url: str, card: dict) -> requests.Response:
4747
response.raise_for_status()
4848
if response.status_code == HTTPStatus.ACCEPTED:
4949
logger.debug(
50-
"Got %s response from Teams webhook, assuming success", HTTPStatus.ACCEPTED
50+
f"Got {HTTPStatus.ACCEPTED} response from Teams webhook, assuming success"
5151
)
5252
return response
5353

@@ -71,13 +71,14 @@ def send_message(
7171
card = format_adaptive_card(body)
7272
try:
7373
response = send_adaptive_card(self.url, card)
74-
# The status code is not reliable for the older version and 202 for the newer version
75-
# The response returns 1 in the body for the old version for success and otherwise some text
76-
# The new version is not reliable to do a check and in the response there is nothing that can be used
77-
# to determine if the message was sent successfully.
78-
if (
79-
response.status_code not in (HTTPStatus.OK, HTTPStatus.ACCEPTED)
80-
or len(response.text) > 1
74+
# For the old teams webhook version of Teams simply returning status code 200
75+
# is not indicating that it was successful.
76+
# In that version they return some text if it was NOT successful, otherwise
77+
# they return the number 1 in the text. For the new teams webhook version they always
78+
# return a 202 and nothing else can be used to determine if the message was
79+
# sent successfully.
80+
if response.status_code not in (HTTPStatus.OK, HTTPStatus.ACCEPTED) or (
81+
response.status_code == HTTPStatus.OK and len(response.text) > 1
8182
):
8283
raise MessagingIntegrationError(
8384
f"Could not post message to Teams via webhook. Status code: {response.status_code}, Error: {response.text}"
@@ -89,7 +90,7 @@ def send_message(
8990
)
9091
except requests.RequestException as e:
9192
raise MessagingIntegrationError(
92-
f"Network error while posting message to Teams webhook: {str(e)}"
93+
f"An error occurred while posting message to Teams webhook: {str(e)}"
9394
) from e
9495

9596
def supports_reply(self) -> bool:

0 commit comments

Comments
 (0)