Update app.py
Browse files
app.py
CHANGED
|
@@ -2,37 +2,33 @@ import telebot
|
|
| 2 |
from fastapi import FastAPI, Request
|
| 3 |
import uvicorn
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
WEBHOOK_URL = "https://astraos-testing.hf.space/webhook"
|
| 8 |
|
| 9 |
bot = telebot.TeleBot(TOKEN, parse_mode="HTML")
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
@
|
| 17 |
-
def
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
bot.run_webhooks(
|
| 25 |
-
listen=
|
| 26 |
-
port=
|
| 27 |
-
url_path=
|
| 28 |
-
webhook_url=WEBHOOK_URL,
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
max_connections=40, # (Optional) Maximum simultaneous connections
|
| 32 |
-
allowed_updates=None, # (Optional) List of update types you want your bot to receive
|
| 33 |
-
ip_address=None, # (Optional) Fixed IP address to use for webhook requests
|
| 34 |
-
drop_pending_updates=False, # (Optional) Drop any pending updates on startup
|
| 35 |
-
timeout=20, # (Optional) Request connection timeout in seconds
|
| 36 |
-
secret_token=None, # (Optional) Secret token for verifying webhook requests
|
| 37 |
-
secret_token_length=20 # (Optional) Length of the secret token (default: 20)
|
| 38 |
)
|
|
|
|
| 2 |
from fastapi import FastAPI, Request
|
| 3 |
import uvicorn
|
| 4 |
|
| 5 |
+
TOKEN = "6655373829:AAGduLdLyNx7zUtxH73Sp3Z1vHKS35tV9WU" # Only needed for bot processing, not for webhook setup
|
| 6 |
+
WEBHOOK_URL = "https://astraos-testing.hf.space/webhook" # Webhook already set up, we just listen
|
|
|
|
| 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 |
+
bot.process_new_updates([update]) # Process the received Telegram update
|
| 16 |
+
return {"status": "ok"}
|
| 17 |
|
| 18 |
+
@app.get("/")
|
| 19 |
+
def home():
|
| 20 |
+
return {"message": "Bot is running via webhook"}
|
| 21 |
|
| 22 |
+
@bot.message_handler(commands=["start"])
|
| 23 |
+
def start_command(message):
|
| 24 |
+
bot.reply_to(message, "Hello! I'm running via FastAPI webhook!")
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
bot.run_webhooks(
|
| 28 |
+
listen="0.0.0.0", # Listen on all available network interfaces
|
| 29 |
+
port=7860, # Use the default FastAPI port (adjust as needed)
|
| 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 |
)
|