skip to Main Content

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


  1. I think that you get the code on telegram and not in the file

    Login or Signup to reply.
  2. 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 method sign_in() instead of connect()

    try:
        await client.sign_in(number, code)
    except Exception as e:
        print('Failed to connect', e, file=sys.stderr)
        return
    

    Reference for sign_in() in docs

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search