Upload telegram_bot.py
Browse files- telegram_bot.py +25 -1
telegram_bot.py
CHANGED
|
@@ -646,7 +646,31 @@ def main():
|
|
| 646 |
logger.info(f"Token: {safe_token}...")
|
| 647 |
|
| 648 |
# Use allowed_updates to reduce unnecessary processing
|
| 649 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 650 |
|
| 651 |
if __name__ == "__main__":
|
| 652 |
main()
|
|
|
|
| 646 |
logger.info(f"Token: {safe_token}...")
|
| 647 |
|
| 648 |
# Use allowed_updates to reduce unnecessary processing
|
| 649 |
+
# Note: When running in Docker with threading, signal handlers may not work
|
| 650 |
+
try:
|
| 651 |
+
app.run_polling(allowed_updates=["message", "callback_query"], close_loop=False)
|
| 652 |
+
except ValueError as e:
|
| 653 |
+
if "add_signal_handler()" in str(e):
|
| 654 |
+
logger.warning("⚠️ Running in non-main thread (Docker), using fallback polling")
|
| 655 |
+
# Fallback for non-main thread execution
|
| 656 |
+
import asyncio
|
| 657 |
+
try:
|
| 658 |
+
loop = asyncio.get_running_loop()
|
| 659 |
+
except RuntimeError:
|
| 660 |
+
loop = asyncio.new_event_loop()
|
| 661 |
+
asyncio.set_event_loop(loop)
|
| 662 |
+
|
| 663 |
+
loop.run_until_complete(app.initialize())
|
| 664 |
+
loop.run_until_complete(app.start())
|
| 665 |
+
logger.info("🤖 Bot polling started (non-signal mode)")
|
| 666 |
+
try:
|
| 667 |
+
loop.run_until_complete(app.updater.start_polling(allowed_updates=["message", "callback_query"]))
|
| 668 |
+
except KeyboardInterrupt:
|
| 669 |
+
pass
|
| 670 |
+
finally:
|
| 671 |
+
loop.run_until_complete(app.stop())
|
| 672 |
+
else:
|
| 673 |
+
raise
|
| 674 |
|
| 675 |
if __name__ == "__main__":
|
| 676 |
main()
|