Skip to content

Commit c24a4da

Browse files
committed
refac
1 parent f949d17 commit c24a4da

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

backend/open_webui/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ def reachable(host: str, port: int) -> bool:
15891589
ENABLE_USER_WEBHOOKS = PersistentConfig(
15901590
'ENABLE_USER_WEBHOOKS',
15911591
'ui.enable_user_webhooks',
1592-
os.environ.get('ENABLE_USER_WEBHOOKS', 'True').lower() == 'true',
1592+
os.environ.get('ENABLE_USER_WEBHOOKS', 'False').lower() == 'true',
15931593
)
15941594

15951595
# FastAPI / AnyIO settings

backend/open_webui/routers/channels.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,12 +815,16 @@ async def get_pinned_channel_messages(
815815
############################
816816

817817

818-
async def send_notification(name, webui_url, channel, message, active_user_ids, db=None):
818+
async def send_notification(request, channel, message, active_user_ids, db=None):
819+
name = request.app.state.WEBUI_NAME
820+
webui_url = request.app.state.config.WEBUI_URL
821+
enable_user_webhooks = request.app.state.config.ENABLE_USER_WEBHOOKS
822+
819823
users = get_channel_users_with_access(channel, 'read', db=db)
820824

821825
for user in users:
822826
if (user.id not in active_user_ids) and Channels.is_user_channel_member(channel.id, user.id, db=db):
823-
if user.settings:
827+
if enable_user_webhooks and user.settings:
824828
webhook_url = user.settings.ui.get('notifications', {}).get('webhook_url', None)
825829
if webhook_url:
826830
await post_webhook(
@@ -1109,8 +1113,7 @@ async def post_new_message(
11091113
async def background_handler():
11101114
await model_response_handler(request, channel, message, user)
11111115
await send_notification(
1112-
request.app.state.WEBUI_NAME,
1113-
request.app.state.config.WEBUI_URL,
1116+
request,
11141117
channel,
11151118
message,
11161119
active_user_ids,

backend/open_webui/utils/middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,7 +3098,7 @@ async def non_streaming_chat_response_handler(response, ctx):
30983098
)
30993099

31003100
# Send a webhook notification if the user is not active
3101-
if not Users.is_user_active(user.id):
3101+
if request.app.state.config.ENABLE_USER_WEBHOOKS and not Users.is_user_active(user.id):
31023102
webhook_url = Users.get_user_webhook_url_by_id(user.id)
31033103
if webhook_url:
31043104
await post_webhook(
@@ -4587,7 +4587,7 @@ def restricted_import(name, globals=None, locals=None, fromlist=(), level=0):
45874587
)
45884588

45894589
# Send a webhook notification if the user is not active
4590-
if not Users.is_user_active(user.id):
4590+
if request.app.state.config.ENABLE_USER_WEBHOOKS and not Users.is_user_active(user.id):
45914591
webhook_url = Users.get_user_webhook_url_by_id(user.id)
45924592
if webhook_url:
45934593
await post_webhook(

0 commit comments

Comments
 (0)