MatteoScript commited on
Commit
09a8c2d
·
verified ·
1 Parent(s): 430a806

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -10
main.py CHANGED
@@ -1,11 +1,11 @@
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,16 +16,16 @@ app.add_middleware(
16
  allow_headers=["*"],
17
  )
18
 
 
 
19
  @app.post("/")
20
- def webhook(req: dict):
21
- print(req)
22
- data = req.json()
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
- return {"response": "aaa"}
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():