bot / app.py
AstraOS's picture
Update app.py
dfa56fa verified
raw
history blame
1.14 kB
import telebot
from fastapi import FastAPI, Request
import uvicorn
# Your bot token is used for processing updates only.
TOKEN = "6655373829:AAGduLdLyNx7zUtxH73Sp3Z1vHKS35tV9WU"
# This is your externally configured webhook URL.
WEBHOOK_URL = "https://astraos-testing.hf.space/webhook"
bot = telebot.TeleBot(TOKEN, parse_mode="HTML")
app = FastAPI()
@app.post("/webhook")
async def telegram_webhook(request: Request):
# Telegram sends update data as JSON to your endpoint.
json_data = await request.json()
update = telebot.types.Update.de_json(json_data)
# Process the received update.
bot.process_new_updates([update])
return {"status": "ok"}
@app.get("/")
def home():
return {"message": "Bot is running via webhook"}
@bot.message_handler(commands=["start"])
def start_command(message):
bot.reply_to(message, "Hello! I'm running via FastAPI webhook!")
if __name__ == "__main__":
# Since the webhook is already set on Telegram, we only need to start the FastAPI server.
# Using uvicorn.run here means we are simply listening on the provided endpoint.
uvicorn.run(app, host="0.0.0.0", port=7860)