Telethon first steps in python
Solution 1:
is this code you are sent in order to generate an app necessary any more?
Yes, like with many online services offering an API, you register your developer account and get a token (in Telegram's case, api_id
and api_hash
combination) that can be used to access the API (at all or with less limitations).
It might seem a bit confusing that your application is bound to your user account, however this doesn't mean it can only be used in your account. You, the developer, create an application, and any other user (or even bot) can run your application using your api_id
and api_hash
.
As an example, when you use Telegram for Android or Telegram Desktop, you are running the application they developed, and are logging in using the api_id
and api_hash
of the respective developers, not your own.
if the phone is not signed up, what other means could have telegram used?
Telegram may send a SMS to the phone number or perform a phone call. You can use https://tl.telethon.dev to find that send code returns, at the time of writing, a SentCode
. This comes with a SentCodeType
which currently can indicate: sent via app, call, flash call, or SMS.
does this mean the phone with which you got your id/hash is is not necessarily the same with which you create the client?
As explained above, the api_id
and api_hash
is for the developer of the application, not the users that will login to your application. When you get started, this person is often the same (you, the developer), but when you publish your application, anyone can sign in without needing to provide their api_id
and api_hash
. Of course, you would need to keep those secret to try to minimize people from using your key in their applications, although this is not really doable.
How is this obtaining the authorization key?
StringSession
embeds the authorization key that was generated to be used for encryption inside the string itself. Next time you use the client, all you need is this key, as Telegram already knows who you are with it, because you signed in before.
How can you specify the phone to which you want to connect?
There is no need. Telegram remembers the account that logged in with a certain authorization key. In official clients, you may see which devices are logged in and terminate their sessions (invalidating their authorization key) to log them out.
Is this a method you can only, or you should only use after the phone has been given access?
You can use StringSession
to login, too, and just print it and reuse it later. In this case, the StringSession
would begin empty, Telethon would generate an authorization key, you would login, and saving the session would produce something that can be reused.
Can you have more than one session for the same number, even if they don't try to connect at the same time?
Yes, this is what happens when you use, for example, Telegram for Android and Telegram Desktop. Adding a third with Telethon is not different.
Can you skip in any way the verification code using for signing up?
No, because Telegram needs to validate the phone exists and is in use.