Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,49 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
import
|
|
|
|
|
|
|
4 |
|
5 |
-
TOKEN = "6655373829:AAGduLdLyNx7zUtxH73Sp3Z1vHKS35tV9WU"
|
6 |
-
WEBHOOK_URL = "https://astraos-testing.hf.space/webhook" # Replace with your actual webhook URL
|
7 |
|
8 |
-
|
|
|
|
|
9 |
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
json_data = await request.json()
|
15 |
-
update = telebot.types.Update.de_json(json_data)
|
16 |
-
bot.process_new_updates([update])
|
17 |
-
return {"status": "ok"}
|
18 |
|
19 |
-
|
20 |
-
def
|
21 |
-
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
bot.remove_webhook()
|
26 |
-
bot.set_webhook(WEBHOOK_URL)
|
27 |
-
print(f"Webhook set to {WEBHOOK_URL}")
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
print("Webhook removed")
|
33 |
|
34 |
-
@bot.message_handler(commands=["start"])
|
35 |
-
def start_command(message):
|
36 |
-
bot.reply_to(message, "Hello! I am a FastAPI Telegram bot!")
|
37 |
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from telegram import Update
|
4 |
+
from telegram.ext import Application, CommandHandler, ContextTypes
|
5 |
+
import logging
|
6 |
+
import threading
|
7 |
|
|
|
|
|
8 |
|
9 |
+
# Enable logging
|
10 |
+
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
11 |
+
logger = logging.getLogger(__name__)
|
12 |
|
13 |
+
# Load bot token from environment variable
|
14 |
+
BOT_TOKEN = "6655373829:AAGduLdLyNx7zUtxH73Sp3Z1vHKS35tV9WU"
|
15 |
+
if not BOT_TOKEN:
|
16 |
+
raise ValueError("Bot token is not set in environment variables")
|
17 |
|
18 |
+
# Create the bot application
|
19 |
+
application = Application.builder().token(BOT_TOKEN).build()
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
# Define the /start command handler
|
22 |
+
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
23 |
+
"""Sends a welcome message when the user starts the bot."""
|
24 |
+
await update.message.reply_text("Hello! This bot is running on Hugging Face Spaces 🚀")
|
25 |
|
26 |
+
# Add command handlers
|
27 |
+
application.add_handler(CommandHandler("start", start))
|
|
|
|
|
|
|
28 |
|
29 |
+
# Function to run the polling
|
30 |
+
def start_polling():
|
31 |
+
application.run_polling()
|
|
|
32 |
|
|
|
|
|
|
|
33 |
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
# Streamlit UI
|
38 |
+
st.title("Telegram Bot on Streamlit")
|
39 |
+
st.write("This bot is running using Streamlit and Python-Telegram-Bot.")
|
40 |
+
|
41 |
+
# Add a text area to show messages (could be used for bot responses)
|
42 |
+
message_area = st.empty()
|
43 |
+
|
44 |
+
# Start a new thread to run polling
|
45 |
+
thread = threading.Thread(target=start_polling)
|
46 |
+
thread.start()
|
47 |
+
|
48 |
+
# Display information
|
49 |
+
st.write("Bot is actively running and polling Telegram.")
|