diff --git a/Getting-Started.md b/Getting-Started.md new file mode 100644 index 0000000..64dc411 --- /dev/null +++ b/Getting-Started.md @@ -0,0 +1,46 @@ +This section provides all the information you need to start using Pyrogram. There are a few steps you have to follow before you can use the library to make API calls. + +## API Keys + +The very first step requires you to obtain a valid Telegram API key. If you already have one you can skip this, otherwise: + +1. Visit https://my.telegram.org/apps and log in with your Telegram Account. +2. Fill out the form to register a new Telegram application. +3. Done. The Telegram API key consists of two parts: the **App api_id** and the **App api_hash**. + +**Important:** This key should be kept secret. + +## Setup + +Create a new `config.ini` file at the root of your working directory, paste the following and replace the **api_id** and **api_hash** values with [your own](#api-keys): + +``` ini +[pyrogram] +api_id = 12345 +api_hash = 0123456789abcdef0123456789abcdef +``` + +## Authorization + +Telegram requires that users be authorized in order to use the API. Pyrogram automatically manages this access, all you need to do is create an instance of the `pyrogram.Client` class by passing to it a `session_name` of your choice and call the `start` method: + +``` python +from pyrogram import Client + +client = Client(session_name="example") +client.start() +``` + +This starts an interactive shell asking you to input your **phone number** (including your [Country Code](https://en.wikipedia.org/wiki/List_of_country_calling_codes)) and the **phone code** you will receive: + +``` +Enter phone number: +39********** +Is "+39**********" correct? (y/n): y +Enter phone code: 32768 +``` + +After successfully authorizing yourself, a new file called `example.session` will be created allowing Pyrogram executing API calls with your identity. + +**Important:** The `*.session` file must be kept secret. + +**Note:** The authorization process is executed only once. However, the code above is always required; as soon as a valid session file exists, Pyrogram will use that and won't ask you to enter your phone number again when you restart your script. \ No newline at end of file