File size: 1,231 Bytes
13f6c83 8dfff44 13f6c83 8dfff44 13f6c83 8dfff44 13f6c83 8dfff44 13f6c83 cc87a2a 13f6c83 cc87a2a 8dfff44 13f6c83 8dfff44 13f6c83 cc87a2a 13f6c83 8dfff44 13f6c83 4e3ddbf |
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 |
import os
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes
import logging
import threading
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
# Load bot token from environment variable
BOT_TOKEN = "6655373829:AAGduLdLyNx7zUtxH73Sp3Z1vHKS35tV9WU"
if not BOT_TOKEN:
raise ValueError("Bot token is not set in environment variables")
# Create the bot application
application = Application.builder().token(BOT_TOKEN).build()
# Define the /start command handler
def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Sends a welcome message when the user starts the bot."""
update.message.reply_text("Hello! This bot is running in synchronous mode π")
# Add command handlers
application.add_handler(CommandHandler("start", start))
# Function to run the polling
def start_polling():
# Run the polling in blocking mode
application.run_polling()
# Start a new thread to run polling
thread = threading.Thread(target=start_polling)
thread.start()
# Display information in terminal/log
print("Bot is actively running and polling Telegram.")
|