Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
|
2 |
from fastapi import FastAPI, Request
|
3 |
from fastapi.middleware.cors import CORSMiddleware # Importa il middleware CORS
|
4 |
|
5 |
TOKEN = "6770617809:AAEhytQUOl3uZOFINVE7-o0KkIoAz8perGU"
|
6 |
BASE_URL = f"https://api.telegram.org/bot{TOKEN}"
|
7 |
|
8 |
-
|
9 |
|
10 |
app = FastAPI()
|
11 |
app.add_middleware(
|
@@ -16,16 +16,16 @@ app.add_middleware(
|
|
16 |
allow_headers=["*"],
|
17 |
)
|
18 |
|
|
|
|
|
19 |
@app.post("/")
|
20 |
-
def webhook(
|
21 |
-
print(req)
|
22 |
-
data = req.json()
|
23 |
print(data)
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
|
30 |
@app.get("/")
|
31 |
def read_general():
|
|
|
1 |
+
import httpx
|
2 |
from fastapi import FastAPI, Request
|
3 |
from fastapi.middleware.cors import CORSMiddleware # Importa il middleware CORS
|
4 |
|
5 |
TOKEN = "6770617809:AAEhytQUOl3uZOFINVE7-o0KkIoAz8perGU"
|
6 |
BASE_URL = f"https://api.telegram.org/bot{TOKEN}"
|
7 |
|
8 |
+
client = httpx.AsyncClient()
|
9 |
|
10 |
app = FastAPI()
|
11 |
app.add_middleware(
|
|
|
16 |
allow_headers=["*"],
|
17 |
)
|
18 |
|
19 |
+
#https://api.telegram.org/bot6770617809:AAEhytQUOl3uZOFINVE7-o0KkIoAz8perGU/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/
|
20 |
+
|
21 |
@app.post("/")
|
22 |
+
def webhook(data: dict):
|
|
|
|
|
23 |
print(data)
|
24 |
+
chat_id = data['message']['chat']['id']
|
25 |
+
text = data['message']['text']
|
26 |
+
await client.get(f"{BASE_URL}/sendMessage?chat_id={chat_id}&text={text}")
|
27 |
+
return data
|
28 |
+
|
29 |
|
30 |
@app.get("/")
|
31 |
def read_general():
|