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()