From 7807a6eac7e3256df37f6b56cb1da591aca90bc3 Mon Sep 17 00:00:00 2001 From: bucolucas Date: Tue, 20 Aug 2024 13:24:45 -0500 Subject: [PATCH] Add functionality to check and send message if semaphore file exists on initialization --- telegram_helper.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/telegram_helper.py b/telegram_helper.py index 8afd5e3..0fbea0c 100644 --- a/telegram_helper.py +++ b/telegram_helper.py @@ -8,6 +8,9 @@ class TelegramHelper: def __init__(self, bot): self.bot = bot 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: await self.bot.start() @@ -93,3 +96,13 @@ class TelegramHelper: logging.info("Bot is running...") application.run_polling() + + def _check_and_send_reboot_message(self): + reboot_file_path = "./.doreboot" + if os.path.exists(reboot_file_path): + 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)