Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,21 @@ import telebot
|
|
2 |
from fastapi import FastAPI, Request
|
3 |
import uvicorn
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
7 |
|
8 |
bot = telebot.TeleBot(TOKEN, parse_mode="HTML")
|
9 |
app = FastAPI()
|
10 |
|
11 |
@app.post("/webhook")
|
12 |
async def telegram_webhook(request: Request):
|
|
|
13 |
json_data = await request.json()
|
14 |
update = telebot.types.Update.de_json(json_data)
|
15 |
-
|
|
|
16 |
return {"status": "ok"}
|
17 |
|
18 |
@app.get("/")
|
@@ -24,11 +28,6 @@ def start_command(message):
|
|
24 |
bot.reply_to(message, "Hello! I'm running via FastAPI webhook!")
|
25 |
|
26 |
if __name__ == "__main__":
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
url_path="/webhook", # Must match the endpoint we defined
|
31 |
-
webhook_url=WEBHOOK_URL, # Already set on Telegram
|
32 |
-
max_connections=40, # Default max connections
|
33 |
-
drop_pending_updates=True # Optional: drop old updates
|
34 |
-
)
|
|
|
2 |
from fastapi import FastAPI, Request
|
3 |
import uvicorn
|
4 |
|
5 |
+
# Your bot token is used for processing updates only.
|
6 |
+
TOKEN = "6655373829:AAGduLdLyNx7zUtxH73Sp3Z1vHKS35tV9WU"
|
7 |
+
# This is your externally configured webhook URL.
|
8 |
+
WEBHOOK_URL = "https://astraos-testing.hf.space/webhook"
|
9 |
|
10 |
bot = telebot.TeleBot(TOKEN, parse_mode="HTML")
|
11 |
app = FastAPI()
|
12 |
|
13 |
@app.post("/webhook")
|
14 |
async def telegram_webhook(request: Request):
|
15 |
+
# Telegram sends update data as JSON to your endpoint.
|
16 |
json_data = await request.json()
|
17 |
update = telebot.types.Update.de_json(json_data)
|
18 |
+
# Process the received update.
|
19 |
+
bot.process_new_updates([update])
|
20 |
return {"status": "ok"}
|
21 |
|
22 |
@app.get("/")
|
|
|
28 |
bot.reply_to(message, "Hello! I'm running via FastAPI webhook!")
|
29 |
|
30 |
if __name__ == "__main__":
|
31 |
+
# Since the webhook is already set on Telegram, we only need to start the FastAPI server.
|
32 |
+
# Using uvicorn.run here means we are simply listening on the provided endpoint.
|
33 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
|