omar1232 commited on
Commit
01430bd
·
verified ·
1 Parent(s): 19c5e3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -29,7 +29,7 @@ async def error_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
29
  )
30
 
31
  # Set up and run the Telegram bot
32
- async def setup_and_run_bot():
33
  if not TELEGRAM_BOT_TOKEN:
34
  print("Telegram bot token not found. Please set TELEGRAM_BOT_TOKEN in the Space secrets.")
35
  return
@@ -57,10 +57,6 @@ async def setup_and_run_bot():
57
  print("Starting Telegram bot...")
58
  await application.run_polling(allowed_updates=Update.ALL_TYPES)
59
 
60
- # Run the bot using the existing event loop
61
  if __name__ == "__main__":
62
- loop = asyncio.get_event_loop()
63
- try:
64
- loop.run_until_complete(setup_and_run_bot())
65
- finally:
66
- loop.close()
 
29
  )
30
 
31
  # Set up and run the Telegram bot
32
+ async def main():
33
  if not TELEGRAM_BOT_TOKEN:
34
  print("Telegram bot token not found. Please set TELEGRAM_BOT_TOKEN in the Space secrets.")
35
  return
 
57
  print("Starting Telegram bot...")
58
  await application.run_polling(allowed_updates=Update.ALL_TYPES)
59
 
60
+ # Run the bot
61
  if __name__ == "__main__":
62
+ asyncio.run(main())