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
fa65be2a
Commit
fa65be2a
authored
Mar 20, 2024
by
Timothy J. Baek
Browse files
refac: post webhook
parent
2481e48a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
2 deletions
+12
-2
backend/apps/web/routers/auths.py
backend/apps/web/routers/auths.py
+1
-0
backend/utils/webhook.py
backend/utils/webhook.py
+11
-2
No files found.
backend/apps/web/routers/auths.py
View file @
fa65be2a
...
@@ -159,6 +159,7 @@ async def signup(request: Request, form_data: SignupForm):
...
@@ -159,6 +159,7 @@ async def signup(request: Request, form_data: SignupForm):
if
request
.
app
.
state
.
WEBHOOK_URL
:
if
request
.
app
.
state
.
WEBHOOK_URL
:
post_webhook
(
post_webhook
(
request
.
app
.
state
.
WEBHOOK_URL
,
request
.
app
.
state
.
WEBHOOK_URL
,
WEBHOOK_MESSAGES
.
USER_SIGNUP
(
user
.
name
),
{
{
"action"
:
"signup"
,
"action"
:
"signup"
,
"message"
:
WEBHOOK_MESSAGES
.
USER_SIGNUP
(
user
.
name
),
"message"
:
WEBHOOK_MESSAGES
.
USER_SIGNUP
(
user
.
name
),
...
...
backend/utils/webhook.py
View file @
fa65be2a
import
requests
import
requests
def
post_webhook
(
url
:
str
,
json
:
dict
)
->
bool
:
def
post_webhook
(
url
:
str
,
message
:
str
,
event_data
:
dict
)
->
bool
:
try
:
try
:
r
=
requests
.
post
(
url
,
json
=
json
)
payload
=
{}
if
"https://hooks.slack.com"
in
url
:
payload
[
"text"
]
=
message
elif
"https://discord.com/api/webhooks"
in
url
:
payload
[
"content"
]
=
message
else
:
payload
=
{
**
event_data
}
r
=
requests
.
post
(
url
,
json
=
payload
)
r
.
raise_for_status
()
r
.
raise_for_status
()
return
True
return
True
except
Exception
as
e
:
except
Exception
as
e
:
...
...
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