Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,38 @@
|
|
| 1 |
-
import
|
| 2 |
-
from
|
| 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 |
-
# Display information in terminal/log
|
| 40 |
-
print("Bot is actively running and polling Telegram.")
|
|
|
|
| 1 |
+
import telebot
|
| 2 |
+
from fastapi import FastAPI, Request
|
| 3 |
+
import uvicorn
|
| 4 |
+
|
| 5 |
+
# Replace with your bot token and externally set webhook URL
|
| 6 |
+
TOKEN = "6655373829:AAGduLdLyNx7zUtxH73Sp3Z1vHKS35tV9WU"
|
| 7 |
+
WEBHOOK_URL = "https://astraos-testing.hf.space/webhook"
|
| 8 |
+
|
| 9 |
+
bot = telebot.TeleBot(TOKEN, parse_mode="HTML")
|
| 10 |
+
|
| 11 |
+
# Define your bot handlers as usual:
|
| 12 |
+
@bot.message_handler(commands=['start'])
|
| 13 |
+
def handle_start(message):
|
| 14 |
+
bot.reply_to(message, "Hello! This is a webhook-only Telebot running with FastAPI.")
|
| 15 |
+
|
| 16 |
+
@bot.message_handler(func=lambda message: True)
|
| 17 |
+
def echo_all(message):
|
| 18 |
+
bot.reply_to(message, f"You said: {message.text}")
|
| 19 |
+
|
| 20 |
+
if __name__ == '__main__':
|
| 21 |
+
# Run the webhook listener.
|
| 22 |
+
# Since you already set up the webhook externally, this call only
|
| 23 |
+
# listens for incoming updates at the given URL path.
|
| 24 |
+
bot.run_webhooks(
|
| 25 |
+
listen='127.0.0.1', # IP address to listen on
|
| 26 |
+
port=443, # Port to listen on (HTTPS)
|
| 27 |
+
url_path='webhook', # The URL path part (i.e. /webhook)
|
| 28 |
+
webhook_url=WEBHOOK_URL, # Your externally set webhook URL
|
| 29 |
+
certificate=None, # (Optional) Path to SSL certificate file
|
| 30 |
+
certificate_key=None, # (Optional) Path to the certificate key file
|
| 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 |
+
)
|
|
|
|
|
|