Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ from dotenv import load_dotenv
|
|
11 |
import os
|
12 |
from starlette.websockets import WebSocketState
|
13 |
from jose import JWTError
|
|
|
14 |
|
15 |
load_dotenv()
|
16 |
|
@@ -103,9 +104,29 @@ def get_current_user(token: str = Depends(OAuth2PasswordRequestForm)):
|
|
103 |
async def submit_query(name: str = Form(...), email: str = Form(...), message: str = Form(...)):
|
104 |
query = {"name": name, "email": email, "message": message, "created_at": datetime.utcnow()}
|
105 |
result = collection.insert_one(query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
query["_id"] = str(result.inserted_id)
|
107 |
|
108 |
total_count = collection.count_documents({})
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
await manager.broadcast({
|
110 |
"event": "new_quote",
|
111 |
"data": {
|
|
|
11 |
import os
|
12 |
from starlette.websockets import WebSocketState
|
13 |
from jose import JWTError
|
14 |
+
import httpx
|
15 |
|
16 |
load_dotenv()
|
17 |
|
|
|
104 |
async def submit_query(name: str = Form(...), email: str = Form(...), message: str = Form(...)):
|
105 |
query = {"name": name, "email": email, "message": message, "created_at": datetime.utcnow()}
|
106 |
result = collection.insert_one(query)
|
107 |
+
|
108 |
+
DISCORD_WEBHOOK_URL = os.environ.get("DISCORD_WEBHOOK_URL") # Add to .env
|
109 |
+
|
110 |
+
async def send_discord_notification(data: dict):
|
111 |
+
content = (
|
112 |
+
f"π© **New Quotation Received**\n"
|
113 |
+
f"π€ **Name:** {data['name']}\n"
|
114 |
+
f"π§ **Email:** {data['email']}\n"
|
115 |
+
f"π¬ **Message:** {data['message']}\n"
|
116 |
+
f"π **Time:** {datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')}"
|
117 |
+
)
|
118 |
+
async with httpx.AsyncClient() as client:
|
119 |
+
await client.post(DISCORD_WEBHOOK_URL, json={"content": content})
|
120 |
+
|
121 |
query["_id"] = str(result.inserted_id)
|
122 |
|
123 |
total_count = collection.count_documents({})
|
124 |
+
|
125 |
+
try:
|
126 |
+
await send_discord_notification(query)
|
127 |
+
except Exception as e:
|
128 |
+
print("[Discord Notification Failed]", e)
|
129 |
+
|
130 |
await manager.broadcast({
|
131 |
"event": "new_quote",
|
132 |
"data": {
|