mine-req / app.py
habulaj's picture
Update app.py
43ba2bf verified
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
import httpx
app = FastAPI()
# CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Modelo da requisição
class DiscordMessage(BaseModel):
content: str
WEBHOOK_URL = "https://discord.com/api/webhooks/1447767523377549425/H5t0BMkGf5yLehBm_FfEg4TXWZOLM9EoV0bStbXsFrhfSGqvbvWFDW2Kdak6dMlUQqjD"
@app.post("/send-discord")
async def send_discord_message(msg: DiscordMessage):
try:
async with httpx.AsyncClient() as client:
response = await client.post(WEBHOOK_URL, json={"content": msg.content})
if response.status_code >= 400:
raise HTTPException(status_code=500, detail="Erro ao enviar mensagem ao Discord")
return {"status": "success", "sent": msg.content}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))