AstraOS commited on
Commit
09f5005
Β·
verified Β·
1 Parent(s): cc87a2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -3,6 +3,7 @@ from telegram import Update
3
  from telegram.ext import Application, CommandHandler, ContextTypes
4
  import logging
5
  import threading
 
6
 
7
  # Enable logging
8
  logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
@@ -17,17 +18,19 @@ if not BOT_TOKEN:
17
  application = Application.builder().token(BOT_TOKEN).build()
18
 
19
  # Define the /start command handler
20
- def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
21
  """Sends a welcome message when the user starts the bot."""
22
- update.message.reply_text("Hello! This bot is running in synchronous mode πŸš€")
23
 
24
  # Add command handlers
25
  application.add_handler(CommandHandler("start", start))
26
 
27
  # Function to run the polling
28
  def start_polling():
29
- # Run the polling in blocking mode
30
- application.run_polling()
 
 
31
 
32
  # Start a new thread to run polling
33
  thread = threading.Thread(target=start_polling)
 
3
  from telegram.ext import Application, CommandHandler, ContextTypes
4
  import logging
5
  import threading
6
+ import asyncio
7
 
8
  # Enable logging
9
  logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
 
18
  application = Application.builder().token(BOT_TOKEN).build()
19
 
20
  # Define the /start command handler
21
+ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
22
  """Sends a welcome message when the user starts the bot."""
23
+ await update.message.reply_text("Hello! This bot is running on Hugging Face Spaces πŸš€")
24
 
25
  # Add command handlers
26
  application.add_handler(CommandHandler("start", start))
27
 
28
  # Function to run the polling
29
  def start_polling():
30
+ # Create a new event loop for this thread
31
+ loop = asyncio.new_event_loop()
32
+ asyncio.set_event_loop(loop)
33
+ loop.run_until_complete(application.run_polling())
34
 
35
  # Start a new thread to run polling
36
  thread = threading.Thread(target=start_polling)