diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index fc749033df..0773504167 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -236,6 +236,8 @@ def __init__( self.plugins = plugins self.no_updates = no_updates self.takeout = takeout + self.load_session_hook = None + self.save_session_hook = None self.dispatcher = Dispatcher(self, workers) @@ -288,14 +290,18 @@ async def start(self): 'More info: https://docs.pyrogram.ml/start/Setup#bot-authorization\n') self.load_config() - await self.load_session() + if callable(self.load_session_hook): + self.load_session_hook(self) + else: + self.load_session() self.load_plugins() self.session = Session( - self, - self.dc_id, - self.auth_key - ) + self, + self.dc_id, + self.auth_key, + self.api_id.encode('utf-8') + ) await self.session.start() self.is_started = True @@ -309,7 +315,10 @@ async def start(self): self.is_bot = True await self.authorize_bot() - self.save_session() + if callable(self.save_session_hook): + self.save_session_hook(self) + else: + self.save_session() if not self.is_bot: if self.takeout: