From 3e513be96343f39a024aad0b4ebd1597352011fb Mon Sep 17 00:00:00 2001 From: Alvin Tang <104285249+alvinttang@users.noreply.github.com> Date: Mon, 9 Mar 2026 05:45:21 +0800 Subject: [PATCH] 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 --- backend/open_webui/utils/webhook.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/utils/webhook.py b/backend/open_webui/utils/webhook.py index eb2688851f..62d35f299f 100644 --- a/backend/open_webui/utils/webhook.py +++ b/backend/open_webui/utils/webhook.py @@ -26,9 +26,14 @@ async def post_webhook(name: str, url: str, message: str, event_data: dict) -> b # Microsoft Teams Webhooks elif "webhook.office.com" in url: 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 = [ {"name": name, "value": value} - for name, value in json.loads(event_data.get("user", {})).items() + for name, value in user_dict.items() ] payload = { "@type": "MessageCard",