refactor: dynamically swap activitySubtitle and activityImage if CUSTOM_NAME has been set

This commit is contained in:
changchiyou 2024-03-26 15:45:36 +08:00
parent 5eac5c54f8
commit 427ca4e3f5
No known key found for this signature in database
GPG key ID: 81CA4B8C5DD85821
2 changed files with 15 additions and 17 deletions

View file

@ -1,29 +1,27 @@
import os
import chromadb
from chromadb import Settings
from base64 import b64encode
from bs4 import BeautifulSoup
from pathlib import Path
import json
import yaml
import os
import shutil
from base64 import b64encode
from pathlib import Path
from secrets import token_bytes
import chromadb
import markdown
import requests
import shutil
from secrets import token_bytes
import yaml
from bs4 import BeautifulSoup
from chromadb import Settings
from constants import ERROR_MESSAGES
try:
from dotenv import load_dotenv, find_dotenv
from dotenv import find_dotenv, load_dotenv
load_dotenv(find_dotenv("../.env"))
except ImportError:
print("dotenv not installed, skipping...")
WEBUI_NAME = "Open WebUI"
WEBUI_FAVICON_URL = "https://openwebui.com/favicon.png"
shutil.copyfile("../build/favicon.png", "./static/favicon.png")
####################################
@ -111,7 +109,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"]

View file

@ -1,7 +1,7 @@
import json
import requests
from config import VERSION
from config import VERSION, WEBUI_FAVICON_URL, WEBUI_NAME
def post_webhook(url: str, message: str, event_data: dict) -> bool:
@ -26,8 +26,8 @@ def post_webhook(url: str, message: str, event_data: dict) -> bool:
"sections": [
{
"activityTitle": message,
"activitySubtitle": f"Open WebUI ({VERSION}) - {action}",
"activityImage": "https://openwebui.com/favicon.png",
"activitySubtitle": f"{WEBUI_NAME} ({VERSION}) - {action}",
"activityImage": WEBUI_FAVICON_URL,
"facts": facts,
"markdown": True,
}