How to implement authorization using a Telegram API?

Active3 hr before
Viewed126 times

5 Answers


Phone call: a synthesized voice will tell the user which verification code to input,When user enters verification code, the auth.signIn method must be used to validate it and possibly sign user in.,The returned auth.SentCode object will contain multiple parameters:,If the message takes too long (timeout seconds) to arrive at the phone, the auth.resendCode method may be invoked to resend a code of type next_type.If the same happens again, you can use auth.resendCode with the next_type returned by the previous call to auth.resendCode.To cancel the verification code use auth.cancelCode.

load more v

2) run a local copy of Webogram modified with console.logs to clearly show you step by step the interactions that are taking place between "a working telegram client" and the telegram servers. This will give you a work-flow of how telegram clients and Telegram really work. ,What this approach will give you is a better understanding and introduction to the primitives used throughout Telegram API, and possibly help you start organizing your own set of functions and routines to handle which you will need for the next steps - implementing other features of the API, since generating an AuthKey is just the beginning.,So far I have been able to implement the telegram authorization completely, but not in your requested language - PHP, I used vb.Net. However, I believe the same logic should apply.,What task am I trying to solve? Well, it's simple: several dozens of users (all of them have a carma like here (+10, -2, +1000 etc.) with relevant group taxonomy: web-masters and customers) have a user profile on my website. After they reach a certain amount of carma and since they are authorized in their profile they are joined to private chats based on Telegram generated for them automatically.


In order to use the API, Telegram requires that users be authorized via their phone numbers. Pyrogram automatically manages this process, all you need to do is create an instance of the Client class by passing to it a session_name of your choice (e.g.: “my_account”) and call the run() method:,Bots are a special kind of users that are authorized via their tokens (instead of phone numbers), which are created by the Bot Father. Bot tokens replace the users’ phone numbers only — you still need to configure a Telegram API key with Pyrogram, even when using bots.,This starts an interactive shell asking you to input your phone number (including your Country Code) and the phone code you will receive in your devices that are already authorized or via SMS:,Once a project is set up, you will still have to follow a few steps before you can actually use Pyrogram to make API calls. This section provides all the information you need in order to authorize yourself as user or bot.

from pyrogram
import Client

app = Client("my_account")
load more v

Login to your Telegram account with the phone number of the developer account to use.,Click under API Development tools.,If you need to use a proxy to access Telegram, you will need to either:,This API ID and hash is the one used by your application, not your phone number. You can use this API ID and hash with any phone number or even for bot accounts.

from telethon
import TelegramClient

# Use your own values from
api_id = 12345
api_hash = '0123456789abcdef0123456789abcdef'

# The first parameter is the.session file name(absolute paths allowed)
with TelegramClient('anon', api_id, api_hash) as client:
   client.loop.run_until_complete(client.send_message('me', 'Hello, myself!'))
load more v

3) No need for signing up, authorization, and constant relogin Using a bot, user passes authorization only once when the bot is added to the chat. Client can use the bot as much as it is necessary, and when there is no need in it anymore, user just blocks the bot. That’s all, easy! No password resets anymore.,It should be something like that in your console tab where the server is launched.,If everything is right, you’ll see the same ngrok address value in front of URL key that you specified when configuring.,Seems that it is the best solution for interaction of the Telegram client (Telegram app) with our project.

  • bottle – for our server; a simple and lightweight WSGI micro web-framework
  • requests – for sending requests to telegram. request lib does not need to be overrepresented. It is universally used throughout the world in a variety of projects.
    Note: you have to install these tools on your computer. We will need them later. For that, open your bash console and install it via pip
pip install bottle requests
load more v

Other "implement-using" queries related to "How to implement authorization using a Telegram API?"