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
e5408995
Unverified
Commit
e5408995
authored
Mar 26, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
Mar 26, 2024
Browse files
Merge pull request #1305 from changchiyou/feat/Teams_Incoming_Webhook
enhance: support Teams Incoming Webhook
parents
cb364f0a
d69dfb7c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
4 deletions
+31
-4
backend/config.py
backend/config.py
+2
-1
backend/utils/webhook.py
backend/utils/webhook.py
+29
-3
No files found.
backend/config.py
View file @
e5408995
...
...
@@ -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"
]
...
...
backend/utils/webhook.py
View file @
e5408995
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
}
...
...
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