forked from open-webui/open-webui
Merge pull request #1305 from changchiyou/feat/Teams_Incoming_Webhook
enhance: support Teams Incoming Webhook
This commit is contained in:
commit
e5408995d8
2 changed files with 31 additions and 4 deletions
|
@ -26,6 +26,7 @@ except ImportError:
|
||||||
log.warning("dotenv not installed, skipping...")
|
log.warning("dotenv not installed, skipping...")
|
||||||
|
|
||||||
WEBUI_NAME = "Open WebUI"
|
WEBUI_NAME = "Open WebUI"
|
||||||
|
WEBUI_FAVICON_URL = "https://openwebui.com/favicon.png"
|
||||||
shutil.copyfile("../build/favicon.png", "./static/favicon.png")
|
shutil.copyfile("../build/favicon.png", "./static/favicon.png")
|
||||||
|
|
||||||
####################################
|
####################################
|
||||||
|
@ -141,7 +142,7 @@ if CUSTOM_NAME:
|
||||||
data = r.json()
|
data = r.json()
|
||||||
if r.ok:
|
if r.ok:
|
||||||
if "logo" in data:
|
if "logo" in data:
|
||||||
url = (
|
WEBUI_FAVICON_URL = url = (
|
||||||
f"https://api.openwebui.com{data['logo']}"
|
f"https://api.openwebui.com{data['logo']}"
|
||||||
if data["logo"][0] == "/"
|
if data["logo"][0] == "/"
|
||||||
else data["logo"]
|
else data["logo"]
|
||||||
|
|
|
@ -1,14 +1,40 @@
|
||||||
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
from config import VERSION, WEBUI_FAVICON_URL, WEBUI_NAME
|
||||||
|
|
||||||
def post_webhook(url: str, message: str, event_data: dict) -> bool:
|
def post_webhook(url: str, message: str, event_data: dict) -> bool:
|
||||||
try:
|
try:
|
||||||
payload = {}
|
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
|
payload["text"] = message
|
||||||
|
# Discord Webhooks
|
||||||
elif "https://discord.com/api/webhooks" in url:
|
elif "https://discord.com/api/webhooks" in url:
|
||||||
payload["content"] = message
|
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:
|
else:
|
||||||
payload = {**event_data}
|
payload = {**event_data}
|
||||||
|
|
||||||
|
@ -17,4 +43,4 @@ def post_webhook(url: str, message: str, event_data: dict) -> bool:
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
return False
|
return False
|
Loading…
Reference in a new issue