TelegramWebhook / main.py
MatteoScript's picture
Update main.py
430a806 verified
raw
history blame
809 Bytes
#import httpx
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware # Importa il middleware CORS
TOKEN = "6770617809:AAEhytQUOl3uZOFINVE7-o0KkIoAz8perGU"
BASE_URL = f"https://api.telegram.org/bot{TOKEN}"
#client = httpx.AsyncClient()
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/")
def webhook(req: dict):
print(req)
data = req.json()
print(data)
#chat_id = data['message']['chat']['id']
#text = data['message']['text']
#await client.get(f"{BASE_URL}/sendMessage?chat_id={chat_id}&text={text}")
#return data
return {"response": "aaa"}
@app.get("/")
def read_general():
return {"response": "Started"}