mirror of
https://github.com/open-webui/open-webui
synced 2024-11-16 13:40:55 +00:00
refac: post webhook
This commit is contained in:
parent
2481e48a3a
commit
fa65be2ad2
@ -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),
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
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:
|
||||||
|
Loading…
Reference in New Issue
Block a user