Skip to content

Commit 3e513be

Browse files
fix: prevent TypeError in Teams webhook when user data is missing (open-webui#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>
1 parent f78b238 commit 3e513be

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

backend/open_webui/utils/webhook.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ async def post_webhook(name: str, url: str, message: str, event_data: dict) -> b
2626
# Microsoft Teams Webhooks
2727
elif "webhook.office.com" in url:
2828
action = event_data.get("action", "undefined")
29+
user_data = event_data.get("user", "{}")
30+
if isinstance(user_data, dict):
31+
user_dict = user_data
32+
else:
33+
user_dict = json.loads(user_data)
2934
facts = [
3035
{"name": name, "value": value}
31-
for name, value in json.loads(event_data.get("user", {})).items()
36+
for name, value in user_dict.items()
3237
]
3338
payload = {
3439
"@type": "MessageCard",

0 commit comments

Comments
 (0)