From c24a4da17dbaddf47e2e0f865c1d602d0ff36ee6 Mon Sep 17 00:00:00 2001 From: Tim Baek Date: Tue, 24 Mar 2026 14:54:29 -0500 Subject: [PATCH] refac --- backend/open_webui/config.py | 2 +- backend/open_webui/routers/channels.py | 11 +++++++---- backend/open_webui/utils/middleware.py | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index a9970647b1..2273f392ff 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -1589,7 +1589,7 @@ ENABLE_MESSAGE_RATING = PersistentConfig( ENABLE_USER_WEBHOOKS = PersistentConfig( 'ENABLE_USER_WEBHOOKS', 'ui.enable_user_webhooks', - os.environ.get('ENABLE_USER_WEBHOOKS', 'True').lower() == 'true', + os.environ.get('ENABLE_USER_WEBHOOKS', 'False').lower() == 'true', ) # FastAPI / AnyIO settings diff --git a/backend/open_webui/routers/channels.py b/backend/open_webui/routers/channels.py index 2d5401fac3..68ea5ff7f8 100644 --- a/backend/open_webui/routers/channels.py +++ b/backend/open_webui/routers/channels.py @@ -815,12 +815,16 @@ async def get_pinned_channel_messages( ############################ -async def send_notification(name, webui_url, channel, message, active_user_ids, db=None): +async def send_notification(request, channel, message, active_user_ids, db=None): + name = request.app.state.WEBUI_NAME + webui_url = request.app.state.config.WEBUI_URL + enable_user_webhooks = request.app.state.config.ENABLE_USER_WEBHOOKS + users = get_channel_users_with_access(channel, 'read', db=db) for user in users: if (user.id not in active_user_ids) and Channels.is_user_channel_member(channel.id, user.id, db=db): - if user.settings: + if enable_user_webhooks and user.settings: webhook_url = user.settings.ui.get('notifications', {}).get('webhook_url', None) if webhook_url: await post_webhook( @@ -1109,8 +1113,7 @@ async def post_new_message( async def background_handler(): await model_response_handler(request, channel, message, user) await send_notification( - request.app.state.WEBUI_NAME, - request.app.state.config.WEBUI_URL, + request, channel, message, active_user_ids, diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 720e8dd573..f6582bf239 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -3098,7 +3098,7 @@ async def non_streaming_chat_response_handler(response, ctx): ) # Send a webhook notification if the user is not active - if not Users.is_user_active(user.id): + if request.app.state.config.ENABLE_USER_WEBHOOKS and not Users.is_user_active(user.id): webhook_url = Users.get_user_webhook_url_by_id(user.id) if webhook_url: await post_webhook( @@ -4587,7 +4587,7 @@ async def streaming_chat_response_handler(response, ctx): ) # Send a webhook notification if the user is not active - if not Users.is_user_active(user.id): + if request.app.state.config.ENABLE_USER_WEBHOOKS and not Users.is_user_active(user.id): webhook_url = Users.get_user_webhook_url_by_id(user.id) if webhook_url: await post_webhook(