Spaces:
Configuration error
Configuration error
| 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__) | |
| # --- Configuration --- | |
| # Get the Bot Token from Hugging Face Secrets. This is still the secure way. | |
| TOKEN = os.getenv("TELEGRAM_TOKEN") | |
| # --- IMPORTANT: Using the pre-generated proxy URL you provided --- | |
| # This URL is now hardcoded directly into the application. | |
| # The `/bot` at the end is required for the library to function correctly. | |
| PREGENERATED_PROXY_URL = "https://tg.lgci.workers.dev/bot" | |
| # --- Bot Command Handler --- | |
| async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| """Sends a confirmation message that the bot is working.""" | |
| logger.info("Received /start command. Replying now.") | |
| await update.message.reply_text( | |
| "Hello! This bot is working using the pre-generated proxy at tg.lgci.workers.dev." | |
| ) | |
| # --- Main Bot Logic --- | |
| def main() -> None: | |
| """The main function to set up and run the bot via the pre-generated proxy.""" | |
| if not TOKEN: | |
| logger.error("FATAL: TELEGRAM_TOKEN not found in Hugging Face Secrets!") | |
| return | |
| logger.info(f"Initializing bot to use pre-generated API base: {PREGENERATED_PROXY_URL}") | |
| # Build the application, telling it to use the hardcoded proxy URL as the API endpoint. | |
| application = Application.builder().token(TOKEN).base_url(PREGENERATED_PROXY_URL).build() | |
| # Register the /start command handler | |
| application.add_handler(CommandHandler("start", start_command)) | |
| # Start polling for updates through the proxy | |
| logger.info("Bot is starting, polling for updates...") | |
| application.run_polling() | |
| if __name__ == "__main__": | |
| main() | |