telegram: Add login code support entered by console during authorization
patch 8d22777b1339caf300a5b2e9b76f7d791ff0ec76
Author: E. Bosch <presidev@AT@gmail.com>
Date: Wed Feb 16 23:22:04 CET 2022
* telegram: Add login code support entered by console during authorization
check, add phone number option in config, required by login code
hunk ./irgramd 71
+ tornado.options.define('phone', default=None, metavar='PHONE_NUMBER', help='Phone number associated with the Telegram account to receive the authorization codes if necessary')
hunk ./telegram.py 6
+import aioconsole
hunk ./telegram.py 25
+ self.phone = settings['phone']
hunk ./telegram.py 65
- if await self.telegram_client.is_user_authorized():
- self.authorized = True
- await self.init_mapping()
+ while not await self.telegram_client.is_user_authorized():
+ self.logger.info('Telegram account not authorized, you must provide the Login code '
+ 'that Telegram will sent you via SMS or another connected client')
+ await self.telegram_client.send_code_request(self.phone)
+ code = await aioconsole.ainput('Login code: ')
+ try:
+ await self.telegram_client.sign_in(code=code)
+ except:
+ pass
+
+ self.logger.info('Telegram account authorized')
+ self.authorized = True
+ await self.init_mapping()