Skip to content

Commit 07a7a8b

Browse files
committed
Deprecate force_sms and sign_up
On the 10th of February, Telegram sent the following message to those with an application registered on https://my.telegram.org. -- Telegram API Update. Hello [REDACTED]. Thank you for contributing to the open Telegram ecosystem by developing your app, [REDACTED]. Please note that due to recent updates to Telegram's handling of SMS and the integration of new SMS providers like Firebase, we are changing the way login codes are handled in third-party apps based on the Telegram API. Starting on 18.02.2023, users logging into third-party apps will only be able to receive login codes via Telegram. It will no longer be possible to request an SMS to log into your app - just like when logging into Telegram's own desktop and web clients. Exactly like with the Telegram Desktop and Web apps, if a user doesn't have a Telegram account yet, they will need to create one first using an official mobile Telegram app. We kindly ask you to update your app's login and signup interfaces to reflect these changes before they go live on 18.02.2023 at 13:00 UTC. This change will not significantly affect users since, according to our research, the vast majority of third-party app users also use official Telegram apps. In the coming months, we expect to offer new tools for third-party developers that will help streamline the login process.
1 parent 0563430 commit 07a7a8b

File tree

5 files changed

+13
-106
lines changed

5 files changed

+13
-106
lines changed

readthedocs/quick-references/client-reference.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Auth
3232
send_code_request
3333
sign_in
3434
qr_login
35-
sign_up
3635
log_out
3736
edit_2fa
3837

readthedocs/quick-references/faq.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ However, you may also be part of a limited country, such as Iran or Russia.
6767
In that case, we have bad news for you. Telegram is much more likely to ban
6868
these numbers, as they are often used to spam other accounts, likely through
6969
the use of libraries like this one. The best advice we can give you is to not
70-
abuse the API, like calling many requests really quickly, and to sign up with
71-
these phones through an official application.
70+
abuse the API, like calling many requests really quickly.
7271

7372
We have also had reports from Kazakhstan and China, where connecting
7473
would fail. To solve these connection problems, you should use a proxy.

telethon/client/auth.py

Lines changed: 11 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ def start(
3434
By default, this method will be interactive (asking for
3535
user input if needed), and will handle 2FA if enabled too.
3636
37-
If the phone doesn't belong to an existing account (and will hence
38-
`sign_up` for a new one), **you are agreeing to Telegram's
39-
Terms of Service. This is required and your account
40-
will be banned otherwise.** See https://telegram.org/tos
41-
and https://core.telegram.org/api/terms.
42-
4337
If the event loop is already running, this method returns a
4438
coroutine that you should await on your own code; otherwise
4539
the loop is ran until said coroutine completes.
@@ -188,7 +182,6 @@ async def _start(
188182
two_step_detected = False
189183

190184
await self.send_code_request(phone, force_sms=force_sms)
191-
sign_up = False # assume login
192185
while attempts < max_attempts:
193186
try:
194187
value = code_callback()
@@ -201,19 +194,12 @@ async def _start(
201194
if not value:
202195
raise errors.PhoneCodeEmptyError(request=None)
203196

204-
if sign_up:
205-
me = await self.sign_up(value, first_name, last_name)
206-
else:
207-
# Raises SessionPasswordNeededError if 2FA enabled
208-
me = await self.sign_in(phone, code=value)
197+
# Raises SessionPasswordNeededError if 2FA enabled
198+
me = await self.sign_in(phone, code=value)
209199
break
210200
except errors.SessionPasswordNeededError:
211201
two_step_detected = True
212202
break
213-
except errors.PhoneNumberOccupiedError:
214-
sign_up = False
215-
except errors.PhoneNumberUnoccupiedError:
216-
sign_up = True
217203
except (errors.PhoneCodeEmptyError,
218204
errors.PhoneCodeExpiredError,
219205
errors.PhoneCodeHashEmptyError,
@@ -383,91 +369,10 @@ async def sign_up(
383369
phone: str = None,
384370
phone_code_hash: str = None) -> 'types.User':
385371
"""
386-
Signs up to Telegram as a new user account.
387-
388-
Use this if you don't have an account yet.
389-
390-
You must call `send_code_request` first.
391-
392-
**By using this method you're agreeing to Telegram's
393-
Terms of Service. This is required and your account
394-
will be banned otherwise.** See https://telegram.org/tos
395-
and https://core.telegram.org/api/terms.
396-
397-
Arguments
398-
code (`str` | `int`):
399-
The code sent by Telegram
400-
401-
first_name (`str`):
402-
The first name to be used by the new account.
403-
404-
last_name (`str`, optional)
405-
Optional last name.
406-
407-
phone (`str` | `int`, optional):
408-
The phone to sign up. This will be the last phone used by
409-
default (you normally don't need to set this).
410-
411-
phone_code_hash (`str`, optional):
412-
The hash returned by `send_code_request`. This can be left as
413-
`None` to use the last hash known for the phone to be used.
414-
415-
Returns
416-
The new created :tl:`User`.
417-
418-
Example
419-
.. code-block:: python
420-
421-
phone = '+34 123 123 123'
422-
await client.send_code_request(phone)
423-
424-
code = input('enter code: ')
425-
await client.sign_up(code, first_name='Anna', last_name='Banana')
372+
This method can no longer be used, and will immediately raise a ``ValueError``.
373+
See `issue #4050 <https://github.com/LonamiWebs/Telethon/issues/4050>`_ for context.
426374
"""
427-
me = await self.get_me()
428-
if me:
429-
return me
430-
431-
# To prevent abuse, one has to try to sign in before signing up. This
432-
# is the current way in which Telegram validates the code to sign up.
433-
#
434-
# `sign_in` will set `_tos`, so if it's set we don't need to call it
435-
# because the user already tried to sign in.
436-
#
437-
# We're emulating pre-layer 104 behaviour so except the right error:
438-
if not self._tos:
439-
try:
440-
return await self.sign_in(
441-
phone=phone,
442-
code=code,
443-
phone_code_hash=phone_code_hash,
444-
)
445-
except errors.PhoneNumberUnoccupiedError:
446-
pass # code is correct and was used, now need to sign in
447-
448-
if self._tos and self._tos.text:
449-
if self.parse_mode:
450-
t = self.parse_mode.unparse(self._tos.text, self._tos.entities)
451-
else:
452-
t = self._tos.text
453-
sys.stderr.write("{}\n".format(t))
454-
sys.stderr.flush()
455-
456-
phone, phone_code_hash = \
457-
self._parse_phone_and_hash(phone, phone_code_hash)
458-
459-
result = await self(functions.auth.SignUpRequest(
460-
phone_number=phone,
461-
phone_code_hash=phone_code_hash,
462-
first_name=first_name,
463-
last_name=last_name
464-
))
465-
466-
if self._tos:
467-
await self(
468-
functions.help.AcceptTermsOfServiceRequest(self._tos.id))
469-
470-
return await self._on_login(result.user)
375+
raise ValueError('Third-party applications cannot sign up for Telegram. See https://github.com/LonamiWebs/Telethon/issues/4050 for details')
471376

472377
async def _on_login(self, user):
473378
"""
@@ -498,7 +403,8 @@ async def send_code_request(
498403
The phone to which the code will be sent.
499404
500405
force_sms (`bool`, optional):
501-
Whether to force sending as SMS.
406+
Whether to force sending as SMS. This has been deprecated.
407+
See `issue #4050 <https://github.com/LonamiWebs/Telethon/issues/4050>`_ for context.
502408
503409
Returns
504410
An instance of :tl:`SentCode`.
@@ -510,6 +416,10 @@ async def send_code_request(
510416
sent = await client.send_code_request(phone)
511417
print(sent)
512418
"""
419+
if force_sms:
420+
warnings.warn('force_sms has been deprecated and no longer works')
421+
force_sms = False
422+
513423
result = None
514424
phone = utils.parse_phone(phone) or self._phone
515425
phone_hash = self._phone_code_hash.get(phone)

telethon_examples/interactive_telegram_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async def init(self):
120120
print('Initial connection failed. Retrying...')
121121
await self.connect()
122122

123-
# If the user hasn't called .sign_in() or .sign_up() yet, they won't
123+
# If the user hasn't called .sign_in() yet, they won't
124124
# be authorized. The first thing you must do is authorize. Calling
125125
# .sign_in() should only be done once as the information is saved on
126126
# the *.session file so you don't need to enter the code every time.

telethon_generator/data/friendly.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
ns,friendly,raw
22
account.AccountMethods,takeout,invokeWithTakeout account.initTakeoutSession account.finishTakeoutSession
33
auth.AuthMethods,sign_in,auth.signIn auth.importBotAuthorization
4-
auth.AuthMethods,sign_up,auth.signUp
54
auth.AuthMethods,send_code_request,auth.sendCode auth.resendCode
65
auth.AuthMethods,log_out,auth.logOut
76
auth.AuthMethods,edit_2fa,account.updatePasswordSettings

0 commit comments

Comments
 (0)