Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
d69dfb7c
Unverified
Commit
d69dfb7c
authored
Mar 27, 2024
by
changchiyou
Browse files
feat: support google chat webhook
https://github.com/open-webui/open-webui/pull/1305/\#issuecomment-2021151237
parent
0b62bbb5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
backend/utils/webhook.py
backend/utils/webhook.py
+6
-4
No files found.
backend/utils/webhook.py
View file @
d69dfb7c
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:
...
@@ -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:
...
@@ -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
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment