Add optional force_sms parameter to .send_code_request()

This commit is contained in:
Lonami Exo 2017-11-04 20:46:02 +01:00
parent c8a0953f8e
commit f381b26790

View File

@ -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
result = self(SendCodeRequest(phone, self.api_id, self.api_hash))
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_code_hash = result.phone_code_hash
self._phone = phone
self._phone_code_hash = result.phone_code_hash
return result
def sign_in(self, phone=None, code=None,