Commit fa65be2a authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

refac: post webhook

parent 2481e48a
......@@ -159,6 +159,7 @@ async def signup(request: Request, form_data: SignupForm):
if request.app.state.WEBHOOK_URL:
post_webhook(
request.app.state.WEBHOOK_URL,
WEBHOOK_MESSAGES.USER_SIGNUP(user.name),
{
"action": "signup",
"message": WEBHOOK_MESSAGES.USER_SIGNUP(user.name),
......
import requests
def post_webhook(url: str, json: dict) -> bool:
def post_webhook(url: str, message: str, event_data: dict) -> bool:
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()
return True
except Exception as e:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment