diff --git a/backend/config.py b/backend/config.py index 40fecf861..27311face 100644 --- a/backend/config.py +++ b/backend/config.py @@ -26,6 +26,7 @@ except ImportError: log.warning("dotenv not installed, skipping...") WEBUI_NAME = "Open WebUI" +WEBUI_FAVICON_URL = "https://openwebui.com/favicon.png" shutil.copyfile("../build/favicon.png", "./static/favicon.png") #################################### @@ -141,7 +142,7 @@ if CUSTOM_NAME: data = r.json() if r.ok: if "logo" in data: - url = ( + WEBUI_FAVICON_URL = url = ( f"https://api.openwebui.com{data['logo']}" if data["logo"][0] == "/" else data["logo"] diff --git a/backend/utils/webhook.py b/backend/utils/webhook.py index 1bc5a6048..ed626d03e 100644 --- a/backend/utils/webhook.py +++ b/backend/utils/webhook.py @@ -1,14 +1,40 @@ +import json import requests - +from config import VERSION, WEBUI_FAVICON_URL, WEBUI_NAME def post_webhook(url: str, message: str, event_data: dict) -> bool: try: payload = {} - if "https://hooks.slack.com" in url: + # Slack and Google Chat Webhooks + if "https://hooks.slack.com" in url or "https://chat.googleapis.com" in url: payload["text"] = message + # Discord Webhooks elif "https://discord.com/api/webhooks" in url: payload["content"] = message + # Microsoft Teams Webhooks + elif "webhook.office.com" in url: + action = event_data.get("action", "undefined") + facts = [ + {"name": name, "value": value} + for name, value in json.loads(event_data.get("user", {})).items() + ] + payload = { + "@type": "MessageCard", + "@context": "http://schema.org/extensions", + "themeColor": "0076D7", + "summary": message, + "sections": [ + { + "activityTitle": message, + "activitySubtitle": f"{WEBUI_NAME} ({VERSION}) - {action}", + "activityImage": WEBUI_FAVICON_URL, + "facts": facts, + "markdown": True, + } + ], + } + # Default Payload else: payload = {**event_data} @@ -17,4 +43,4 @@ def post_webhook(url: str, message: str, event_data: dict) -> bool: return True except Exception as e: print(e) - return False + return False \ No newline at end of file