File size: 1,607 Bytes
a86ae4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
import os
import logging
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes

# --- Basic Setup ---
logging.basicConfig(
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
logger = logging.getLogger(__name__)

# --- Get Token from Hugging Face Secrets ---
TOKEN = os.getenv("TELEGRAM_TOKEN")

# --- Define the alternative Telegram API domain ---
# This is the most important part of our test!
ALT_API_URL = "https://api.tele.gs/bot"


# --- Bot Command Handler ---
async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
    """Sends a confirmation message that the trick is working."""
    logger.info("Received /start command. Replying now.")
    await update.message.reply_text(
        "Hello World! If you are seeing this, the trick worked! "
        f"This bot is talking to Telegram via: {ALT_API_URL}"
    )


# --- Main Bot Logic ---
def main() -> None:
    """Start the bot using the alternative domain."""
    if not TOKEN:
        logger.error("FATAL: TELEGRAM_TOKEN not found in Hugging Face Secrets!")
        return

    logger.info(f"Initializing bot to use API base: {ALT_API_URL}")

    # Create the Application and explicitly set the base_url
    application = Application.builder().token(TOKEN).base_url(ALT_API_URL).build()

    # Register the /start command handler
    application.add_handler(CommandHandler("start", start_command))

    # Start polling
    logger.info("Bot is starting, polling for updates...")
    application.run_polling()


if __name__ == "__main__":
    main()