Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,43 +3,50 @@ import logging
|
|
| 3 |
from telegram import Update
|
| 4 |
from telegram.ext import Application, CommandHandler, ContextTypes
|
| 5 |
|
| 6 |
-
#
|
| 7 |
logging.basicConfig(
|
| 8 |
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
|
| 9 |
)
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
|
| 12 |
-
#
|
|
|
|
| 13 |
TOKEN = os.getenv("TELEGRAM_TOKEN")
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 18 |
-
"""Sends a
|
| 19 |
-
logger.info(
|
| 20 |
-
await update.message.reply_text(
|
|
|
|
|
|
|
| 21 |
|
| 22 |
|
|
|
|
| 23 |
def main() -> None:
|
| 24 |
-
"""The main function to set up and run the bot."""
|
| 25 |
if not TOKEN:
|
| 26 |
-
logger.error("FATAL: TELEGRAM_TOKEN not found in
|
| 27 |
return
|
| 28 |
|
| 29 |
-
logger.info("Initializing bot
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
application = Application.builder().token(TOKEN).build()
|
| 34 |
|
| 35 |
# Register the /start command handler
|
| 36 |
application.add_handler(CommandHandler("start", start_command))
|
| 37 |
|
| 38 |
-
# Start
|
| 39 |
logger.info("Bot is starting, polling for updates...")
|
| 40 |
application.run_polling()
|
| 41 |
|
| 42 |
|
| 43 |
if __name__ == "__main__":
|
| 44 |
main()
|
| 45 |
-
|
|
|
|
| 3 |
from telegram import Update
|
| 4 |
from telegram.ext import Application, CommandHandler, ContextTypes
|
| 5 |
|
| 6 |
+
# --- Basic Setup ---
|
| 7 |
logging.basicConfig(
|
| 8 |
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
|
| 9 |
)
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
|
| 12 |
+
# --- Configuration ---
|
| 13 |
+
# Get the Bot Token from Hugging Face Secrets. This is still the secure way.
|
| 14 |
TOKEN = os.getenv("TELEGRAM_TOKEN")
|
| 15 |
|
| 16 |
+
# --- IMPORTANT: Using the pre-generated proxy URL you provided ---
|
| 17 |
+
# This URL is now hardcoded directly into the application.
|
| 18 |
+
# The `/bot` at the end is required for the library to function correctly.
|
| 19 |
+
PREGENERATED_PROXY_URL = "https://tg.lgci.workers.dev/bot"
|
| 20 |
|
| 21 |
+
|
| 22 |
+
# --- Bot Command Handler ---
|
| 23 |
async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 24 |
+
"""Sends a confirmation message that the bot is working."""
|
| 25 |
+
logger.info("Received /start command. Replying now.")
|
| 26 |
+
await update.message.reply_text(
|
| 27 |
+
"Hello! This bot is working using the pre-generated proxy at tg.lgci.workers.dev."
|
| 28 |
+
)
|
| 29 |
|
| 30 |
|
| 31 |
+
# --- Main Bot Logic ---
|
| 32 |
def main() -> None:
|
| 33 |
+
"""The main function to set up and run the bot via the pre-generated proxy."""
|
| 34 |
if not TOKEN:
|
| 35 |
+
logger.error("FATAL: TELEGRAM_TOKEN not found in Hugging Face Secrets!")
|
| 36 |
return
|
| 37 |
|
| 38 |
+
logger.info(f"Initializing bot to use pre-generated API base: {PREGENERATED_PROXY_URL}")
|
| 39 |
|
| 40 |
+
# Build the application, telling it to use the hardcoded proxy URL as the API endpoint.
|
| 41 |
+
application = Application.builder().token(TOKEN).base_url(PREGENERATED_PROXY_URL).build()
|
|
|
|
| 42 |
|
| 43 |
# Register the /start command handler
|
| 44 |
application.add_handler(CommandHandler("start", start_command))
|
| 45 |
|
| 46 |
+
# Start polling for updates through the proxy
|
| 47 |
logger.info("Bot is starting, polling for updates...")
|
| 48 |
application.run_polling()
|
| 49 |
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|
| 52 |
main()
|
|
|