forked from open-webui/open-webui
feat: support google chat webhook
https://github.com/open-webui/open-webui/pull/1305/\#issuecomment-2021151237
This commit is contained in:
parent
0b62bbb52e
commit
d69dfb7c8b
1 changed files with 6 additions and 4 deletions
|
@ -1,17 +1,18 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from config import VERSION, WEBUI_FAVICON_URL, WEBUI_NAME
|
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:
|
elif "webhook.office.com" in url:
|
||||||
action = event_data.get("action", "undefined")
|
action = event_data.get("action", "undefined")
|
||||||
facts = [
|
facts = [
|
||||||
|
@ -33,6 +34,7 @@ def post_webhook(url: str, message: str, event_data: dict) -> bool:
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
# Default Payload
|
||||||
else:
|
else:
|
||||||
payload = {**event_data}
|
payload = {**event_data}
|
||||||
|
|
||||||
|
@ -41,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