From 423fee347a9b15e8cf00e929c1c29ae2353b7f43 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 20 Dec 2024 23:05:22 -0800 Subject: [PATCH 1/2] refac: discord webhook --- backend/open_webui/utils/webhook.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/utils/webhook.py b/backend/open_webui/utils/webhook.py index e6e10884a..d4bdbdb4f 100644 --- a/backend/open_webui/utils/webhook.py +++ b/backend/open_webui/utils/webhook.py @@ -19,7 +19,11 @@ def post_webhook(url: str, message: str, event_data: dict) -> bool: payload["text"] = message # Discord Webhooks elif "https://discord.com/api/webhooks" in url: - payload["content"] = message + payload["content"] = ( + message + if len(message) > 2000 + else f"{message[: 2000 - 14]}... (truncated)" + ) # Microsoft Teams Webhooks elif "webhook.office.com" in url: action = event_data.get("action", "undefined") From de2825bb89d9fdd0586950e9c93eb7dae872b6a0 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 20 Dec 2024 23:09:40 -0800 Subject: [PATCH 2/2] refac --- backend/open_webui/utils/middleware.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index d876539de..9261c26b3 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -608,15 +608,16 @@ async def process_chat_response(request, response, user, events, metadata, tasks is None ): webhook_url = Users.get_user_webhook_url_by_id(user.id) + webui_url = f"{request.headers.get('x-forwarded-proto', request.url.scheme)}://{request.headers.get('x-forwarded-host', f'{request.client.host}:{request.url.port}')}" if webhook_url: post_webhook( webhook_url, - f"{title} - {WEBUI_URL}/c/{metadata['chat_id']}\n\n{content}", + f"{title} - {webui_url}/c/{metadata['chat_id']}\n\n{content}", { "action": "chat", "message": content, "title": title, - "url": f"{WEBUI_URL}/c/{metadata['chat_id']}", + "url": f"{webui_url}/c/{metadata['chat_id']}", }, )