File size: 1,901 Bytes
a6e3f28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import telebot
from fastapi import FastAPI, Request
import uvicorn

# Replace with your bot token and externally set webhook URL
TOKEN = "6655373829:AAGduLdLyNx7zUtxH73Sp3Z1vHKS35tV9WU"
WEBHOOK_URL = "https://astraos-testing.hf.space/webhook"

bot = telebot.TeleBot(TOKEN, parse_mode="HTML")

# Define your bot handlers as usual:
@bot.message_handler(commands=['start'])
def handle_start(message):
    bot.reply_to(message, "Hello! This is a webhook-only Telebot running with FastAPI.")

@bot.message_handler(func=lambda message: True)
def echo_all(message):
    bot.reply_to(message, f"You said: {message.text}")

if __name__ == '__main__':
    # Run the webhook listener.
    # Since you already set up the webhook externally, this call only
    # listens for incoming updates at the given URL path.
    bot.run_webhooks(
        listen='127.0.0.1',          # IP address to listen on
        port=443,                    # Port to listen on (HTTPS)
        url_path='webhook',          # The URL path part (i.e. /webhook)
        webhook_url=WEBHOOK_URL,     # Your externally set webhook URL
        certificate=None,            # (Optional) Path to SSL certificate file
        certificate_key=None,        # (Optional) Path to the certificate key file
        max_connections=40,          # (Optional) Maximum simultaneous connections
        allowed_updates=None,        # (Optional) List of update types you want your bot to receive
        ip_address=None,             # (Optional) Fixed IP address to use for webhook requests
        drop_pending_updates=False,  # (Optional) Drop any pending updates on startup
        timeout=20,                  # (Optional) Request connection timeout in seconds
        secret_token=None,           # (Optional) Secret token for verifying webhook requests
        secret_token_length=20       # (Optional) Length of the secret token (default: 20)
    )