File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -542,6 +542,20 @@ async def restore_agent_routines(application: Application) -> int:
542542 return restored
543543
544544
545+ async def send_to_telegram (self , chat_id : int , message : str , parse_mode : str = "Markdown" ):
546+ """Sends a message to a specific Telegram chat."""
547+ await self .bot .send_message (chat_id = chat_id , text = message , parse_mode = parse_mode )
548+
549+
550+ async def send_to_all (self , message : str , parse_mode : str = "Markdown" ):
551+ """Sends a message to all users who have started the bot."""
552+ for chat_id in self .user_data :
553+ try :
554+ await self .bot .send_message (chat_id = chat_id , text = message , parse_mode = parse_mode )
555+ except Exception as e :
556+ logger .warning (f"Failed to send message to chat { chat_id } : { e } " )
557+
558+
545559def main () -> None :
546560 """Run the bot."""
547561 # Setup persistence to save user data, chat data, and bot data
@@ -579,4 +593,7 @@ async def post_shutdown(application: Application) -> None:
579593
580594
581595if __name__ == "__main__" :
596+ # Add custom methods to the application object
597+ Application .send_to_telegram = send_to_telegram
598+ Application .send_to_all = send_to_all
582599 main ()
You can’t perform that action at this time.
0 commit comments