I am using telethon to automate some tasks on Telegram.
I am trying to create an API where third party users can provide phone number and enter code through an api. I have got the phone number part working, As I allow users to input their phone number through a webservice, this gets wrote to a file, then I am opening that file and fetching the phone number in python which is {number}, I then connect to the client using below.
client = TelegramClient(f'{number}', API_ID, API_KEY)
try:
await client.connect()
except Exception as e:
print('Failed to connect', e, file=sys.stderr)
return
Once the code is run the user enters the verification code (not in the python app) which gets wrote to a file.
And in python the following is returned
Please enter the code you received:
I can open the file which contains the verification code which as {code}
but how do I use {code} to reply to ‘Please enter the code you received:’
Thanks
2
Answers
I think that you get the code on telegram and not in the file
It is possible, but this will be very complex as the code is sent to another device. You can write custom Telegram client that will send this code to your program, but it is too complex and in 99.9% of cases you won’t need it.
Edit:
If you already have this code, let’s say in
code
variable, you can try to use methodsign_in()
instead ofconnect()
Reference for sign_in() in docs