|
import os |
|
import streamlit as st |
|
from telegram import Update |
|
from telegram.ext import Application, CommandHandler, ContextTypes |
|
import logging |
|
import asyncio |
|
import threading |
|
|
|
app = FastAPI() |
|
|
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) |
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
BOT_TOKEN = "6655373829:AAGduLdLyNx7zUtxH73Sp3Z1vHKS35tV9WU" |
|
if not BOT_TOKEN: |
|
raise ValueError("Bot token is not set in environment variables") |
|
|
|
|
|
application = Application.builder().token(BOT_TOKEN).build() |
|
|
|
|
|
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: |
|
await update.message.reply_text("Hello! This bot is running on Hugging Face Spaces π") |
|
|
|
|
|
application.add_handler(CommandHandler("start", start)) |
|
|
|
|
|
def run_polling(): |
|
loop = asyncio.new_event_loop() |
|
asyncio.set_event_loop(loop) |
|
loop.run_until_complete(application.run_polling(close_loop=True)) |
|
|
|
|
|
st.title("Telegram Bot on Streamlit") |
|
st.write("This bot is running using Streamlit and Python-Telegram-Bot.") |
|
|
|
|
|
if st.button("Start Bot"): |
|
thread = threading.Thread(target=run_polling, daemon=True) |
|
thread.start() |
|
st.write("Bot started successfully and is now polling Telegram!") |