mirror of
https://github.com/open-webui/open-webui
synced 2024-11-28 23:13:30 +00:00
Merge pull request #1305 from changchiyou/feat/Teams_Incoming_Webhook
enhance: support Teams Incoming Webhook
This commit is contained in:
commit
e5408995d8
@ -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"]
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user