|
|
from fastapi import FastAPI, HTTPException |
|
|
from fastapi.middleware.cors import CORSMiddleware |
|
|
from pydantic import BaseModel |
|
|
import httpx |
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
|
|
|
app.add_middleware( |
|
|
CORSMiddleware, |
|
|
allow_origins=["*"], |
|
|
allow_credentials=True, |
|
|
allow_methods=["*"], |
|
|
allow_headers=["*"], |
|
|
) |
|
|
|
|
|
|
|
|
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)) |