Answer the question
In order to leave comments, you need to log in
How to enter text into the command line through a bot in a telegram?
To create a client file, you must fill in the phone number and authentication code. I want to implement their input through a bot in telegrams. How can you enter text on the command line? In which direction to move? telethon library.
The creation of such sessions occurs through:
client = TelegramClient('session_test', api_id, api_hash)
client.start()
Answer the question
In order to leave comments, you need to log in
client.start() can take a coroutine as an argument. I use it just the way you describe.
I don't have the code, but I'll try
async def GetCode(self, timeout):
while not self.code and timeout > int(time.time()):
self.project = await self.getDB()
bot_last_message = self.project.bot_last_message.split(":")
if bot_last_message:
message_type = bot_last_message[0]
if message_type == "telegram_code":
telegram_code = bot_last_message[2]
self.code = telegram_code
await self.clear_bot_last_message()
return self.code
await asyncio.sleep(1)
return None
client.start(phone, code_callback=self.GetCode)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question