fix runtime errors in telegram_helper
This commit is contained in:
+5
-14
@@ -8,9 +8,6 @@ class TelegramHelper:
|
|||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.telegram_bot_token = os.getenv('TELEGRAM_BOT_TOKEN')
|
self.telegram_bot_token = os.getenv('TELEGRAM_BOT_TOKEN')
|
||||||
|
|
||||||
# Call the method to check for reboot file and send message
|
|
||||||
self._check_and_send_reboot_message()
|
|
||||||
|
|
||||||
async def start(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def start(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
await self.bot.start()
|
await self.bot.start()
|
||||||
@@ -95,14 +92,8 @@ class TelegramHelper:
|
|||||||
application.add_handler(CallbackQueryHandler(self.abort_processing, pattern='^abort$'))
|
application.add_handler(CallbackQueryHandler(self.abort_processing, pattern='^abort$'))
|
||||||
|
|
||||||
logging.info("Bot is running...")
|
logging.info("Bot is running...")
|
||||||
application.run_polling()
|
|
||||||
|
if os.path.exists("./.doreboot"):
|
||||||
def _check_and_send_reboot_message(self):
|
os.remove("./.doreboot")
|
||||||
reboot_file_path = "./.doreboot"
|
|
||||||
if os.path.exists(reboot_file_path):
|
application.run_polling()
|
||||||
with open(reboot_file_path, 'r') as f:
|
|
||||||
chat_id = f.read().strip()
|
|
||||||
if chat_id:
|
|
||||||
message = "The application has been successfully initialized after a reboot."
|
|
||||||
application = Application.builder().token(self.telegram_bot_token).build()
|
|
||||||
application.bot.send_message(chat_id=chat_id, text=message)
|
|
||||||
Reference in New Issue
Block a user