import telebot from fastapi import FastAPI, Request import uvicorn TOKEN = "6655373829:AAGduLdLyNx7zUtxH73Sp3Z1vHKS35tV9WU" # Only needed for bot processing, not for webhook setup WEBHOOK_URL = "https://astraos-testing.hf.space/webhook" # Webhook already set up, we just listen bot = telebot.TeleBot(TOKEN, parse_mode="HTML") app = FastAPI() @app.post("/webhook") async def telegram_webhook(request: Request): json_data = await request.json() update = telebot.types.Update.de_json(json_data) bot.process_new_updates([update]) # Process the received Telegram update return {"status": "ok"} @app.get("/") def home(): return {"message": "Bot is running via webhook"} @app.message_handler(commands=["start"]) def start_command(message): bot.reply_to(message, "Hello! I'm running via FastAPI webhook!") if __name__ == "__main__": bot.run_webhooks( listen="0.0.0.0", # Listen on all available network interfaces port=7860, # Use the default FastAPI port (adjust as needed) url_path="/webhook", # Must match the endpoint we defined webhook_url=WEBHOOK_URL, # Already set on Telegram max_connections=40, # Default max connections drop_pending_updates=True # Optional: drop old updates )