fix: prevent TypeError in Teams webhook when user data is missing (#22444)
json.loads(event_data.get("user", {})) crashes with TypeError when
the "user" key is absent because the default value {} is a dict, not
a JSON string. json.loads expects str/bytes, not dict.
Also handle the case where "user" is already a dict (not serialized
JSON) to make the webhook more robust.
Co-authored-by: gambletan <ethanchang32@gmail.com>
This commit is contained in:
@@ -26,9 +26,14 @@ async def post_webhook(name: str, url: str, message: str, event_data: dict) -> b
|
|||||||
# Microsoft Teams Webhooks
|
# Microsoft Teams Webhooks
|
||||||
elif "webhook.office.com" in url:
|
elif "webhook.office.com" in url:
|
||||||
action = event_data.get("action", "undefined")
|
action = event_data.get("action", "undefined")
|
||||||
|
user_data = event_data.get("user", "{}")
|
||||||
|
if isinstance(user_data, dict):
|
||||||
|
user_dict = user_data
|
||||||
|
else:
|
||||||
|
user_dict = json.loads(user_data)
|
||||||
facts = [
|
facts = [
|
||||||
{"name": name, "value": value}
|
{"name": name, "value": value}
|
||||||
for name, value in json.loads(event_data.get("user", {})).items()
|
for name, value in user_dict.items()
|
||||||
]
|
]
|
||||||
payload = {
|
payload = {
|
||||||
"@type": "MessageCard",
|
"@type": "MessageCard",
|
||||||
|
|||||||
Reference in New Issue
Block a user