mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-03 05:04:33 +03:00
Add optional force_sms parameter to .send_code_request()
This commit is contained in:
parent
c8a0953f8e
commit
f381b26790
|
@ -23,7 +23,7 @@ from .tl.functions.account import (
|
|||
)
|
||||
from .tl.functions.auth import (
|
||||
CheckPasswordRequest, LogOutRequest, SendCodeRequest, SignInRequest,
|
||||
SignUpRequest, ImportBotAuthorizationRequest
|
||||
SignUpRequest, ResendCodeRequest, ImportBotAuthorizationRequest
|
||||
)
|
||||
from .tl.functions.contacts import (
|
||||
GetContactsRequest, ResolveUsernameRequest
|
||||
|
@ -129,16 +129,29 @@ class TelegramClient(TelegramBareClient):
|
|||
|
||||
# region Authorization requests
|
||||
|
||||
def send_code_request(self, phone):
|
||||
def send_code_request(self, phone, force_sms=False):
|
||||
"""Sends a code request to the specified phone number.
|
||||
|
||||
:param str | int phone: The phone to which the code will be sent.
|
||||
:return auth.SentCode: Information about the result of the request.
|
||||
:param str | int phone:
|
||||
The phone to which the code will be sent.
|
||||
:param bool force_sms:
|
||||
Whether to force sending as SMS. You should call it at least
|
||||
once before without this set to True first.
|
||||
:return auth.SentCode:
|
||||
Information about the result of the request.
|
||||
"""
|
||||
phone = EntityDatabase.parse_phone(phone) or self._phone
|
||||
if force_sms:
|
||||
if not self._phone_code_hash:
|
||||
raise ValueError(
|
||||
'You must call this method without force_sms at least once.'
|
||||
)
|
||||
result = self(ResendCodeRequest(phone, self._phone_code_hash))
|
||||
else:
|
||||
result = self(SendCodeRequest(phone, self.api_id, self.api_hash))
|
||||
self._phone = phone
|
||||
self._phone_code_hash = result.phone_code_hash
|
||||
|
||||
self._phone = phone
|
||||
return result
|
||||
|
||||
def sign_in(self, phone=None, code=None,
|
||||
|
|
Loading…
Reference in New Issue
Block a user