bot / app.py
AstraOS's picture
Update app.py
13f6c83 verified
raw
history blame
1.44 kB
import os
import streamlit as st
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
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Sends a welcome message when the user starts the bot."""
await update.message.reply_text("Hello! This bot is running on Hugging Face Spaces πŸš€")
# Add command handlers
application.add_handler(CommandHandler("start", start))
# Function to run the polling
def start_polling():
application.run_polling()
# Streamlit UI
st.title("Telegram Bot on Streamlit")
st.write("This bot is running using Streamlit and Python-Telegram-Bot.")
# Add a text area to show messages (could be used for bot responses)
message_area = st.empty()
# Start a new thread to run polling
thread = threading.Thread(target=start_polling)
thread.start()
# Display information
st.write("Bot is actively running and polling Telegram.")