SendCodeRequest

Only users can use this request. See code examples.

---functions---
auth.sendCode#a677244f phone_number:string api_id:int api_hash:string settings:CodeSettings = auth.SentCode

Returns

auth.SentCode

This type can be an instance of either:

SentCodeSentCodeSuccess

Parameters

phone_numberstring
api_idint
api_hashstring
settingsCodeSettings

Known RPC errors

This request can cause 10 known errors:

ApiIdInvalidErrorThe api_id/api_hash combination is invalid.
ApiIdPublishedFloodErrorThis API id was published somewhere, you can't use it now.
AuthRestartErrorRestart the authorization process.
InputRequestTooLongErrorThe input request was too long. This may be a bug in the library as it can occur when serializing more bytes than it should (like appending the vector constructor code at the end of a message).
PhoneNumberAppSignupForbiddenErrorYou can't sign up using this app.
PhoneNumberBannedErrorThe used phone number has been banned from Telegram and cannot be used anymore. Maybe check https://www.telegram.org/faq_spam.
PhoneNumberFloodErrorYou asked for the code too many times..
PhoneNumberInvalidErrorThe phone number is invalid.
PhonePasswordFloodErrorYou have tried logging in too many times.
PhonePasswordProtectedErrorThis phone is password protected.

You can import these from telethon.errors.

Example

Please refer to the documentation of client.send_code_request() to learn about the parameters and see several code examples on how to use it.

The method above is the recommended way to do it. If you need more control over the parameters or want to learn how it is implemented, open the details by clicking on the "Details" text.

from telethon.sync import TelegramClient
from telethon import functions, types

with TelegramClient(name, api_id, api_hash) as client:
    result = client(functions.auth.SendCodeRequest(
        phone_number='some string here',
        api_id=42,
        api_hash='some string here',
        settings=types.CodeSettings(
            allow_flashcall=True,
            current_number=True,
            allow_app_hash=True,
            allow_missed_call=True,
            allow_firebase=True,
            unknown_number=True,
            logout_tokens=[b'arbitrary\x7f data \xfa here'],
            token='some string here',
            app_sandbox=False
        )
    ))
    print(result.stringify())