Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,8 +28,8 @@ async def error_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
| 28 |
text="Bot conflict detected. Restarting..."
|
| 29 |
)
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
async def
|
| 33 |
if not TELEGRAM_BOT_TOKEN:
|
| 34 |
print("Telegram bot token not found. Please set TELEGRAM_BOT_TOKEN in the Space secrets.")
|
| 35 |
return
|
|
@@ -53,10 +53,14 @@ async def run_telegram_bot():
|
|
| 53 |
except Exception as e:
|
| 54 |
print(f"Error clearing updates: {e}")
|
| 55 |
|
| 56 |
-
# Start the bot
|
| 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
text="Bot conflict detected. Restarting..."
|
| 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
|
|
|
|
| 53 |
except Exception as e:
|
| 54 |
print(f"Error clearing updates: {e}")
|
| 55 |
|
| 56 |
+
# Start the 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()
|