File size: 1,044 Bytes
8dfff44 af77e3b 8dfff44 af77e3b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import telebot
from fastapi import FastAPI, Request
import uvicorn
TOKEN = "6655373829:AAGduLdLyNx7zUtxH73Sp3Z1vHKS35tV9WU"
WEBHOOK_URL = "https://astraos-testing.hf.space/webhook" # Replace with your actual webhook URL
bot = telebot.TeleBot(TOKEN, parse_mode="HTML")
app = FastAPI()
@app.post("/webhook")
async def webhook(request: Request):
json_data = await request.json()
update = telebot.types.Update.de_json(json_data)
bot.process_new_updates([update])
return {"status": "ok"}
@app.get("/")
def home():
return {"message": "Bot is running"}
@app.on_event("startup")
async def on_startup():
bot.remove_webhook()
bot.set_webhook(WEBHOOK_URL)
print(f"Webhook set to {WEBHOOK_URL}")
@app.on_event("shutdown")
async def on_shutdown():
bot.remove_webhook()
print("Webhook removed")
@bot.message_handler(commands=["start"])
def start_command(message):
bot.reply_to(message, "Hello! I am a FastAPI Telegram bot!")
# if __name__ == "__main__":
# uvicorn.run(app, host="0.0.0.0", port=7860)
|