feat: support google chat webhook

https://github.com/open-webui/open-webui/pull/1305/\#issuecomment-2021151237
This commit is contained in:
changchiyou 2024-03-27 10:25:57 +08:00
parent 0b62bbb52e
commit d69dfb7c8b
No known key found for this signature in database
GPG key ID: 81CA4B8C5DD85821

View file

@ -1,17 +1,18 @@
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 = [
@ -33,6 +34,7 @@ def post_webhook(url: str, message: str, event_data: dict) -> bool:
}
],
}
# Default Payload
else:
payload = {**event_data}
@ -41,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