Documentation Index
Fetch the complete documentation index at: https://mintlify.com/danog/MadelineProto/llms.txt
Use this file to discover all available pages before exploring further.
Overview
MadelineProto supports multiple authentication methods for both bots and user accounts. The login flow depends on your use case and account type.Bot Login
The simplest login method uses a bot token obtained from @BotFather:Bot Login with Event Handler
For bots using event handlers, use thestartAndLoopBot method:
EventHandler.php:171:
- Initializes the API client
- Performs bot authentication
- Starts the event handler loop
- Sets up error reporting
User Login (Phone Number)
User accounts require a multi-step authentication process:Step 1: Send Code
phoneLogin method (Wrappers/Login.php:192):
- Sends an SMS/Telegram code to the phone number
- Returns authorization info
- Sets login state to
API::WAITING_CODE
Step 2: Complete Login
Handling 2FA
If two-factor authentication is enabled:Wrappers/Login.php:334, the complete2faLogin method:
- Verifies the 2FA password
- Completes the authentication process
- Updates login state to
API::LOGGED_IN
Handling Signup
If the phone number is not registered:QR Code Login
For user accounts, MadelineProto supports QR code login:qrLogin method (Wrappers/Login.php:92):
- Generates a login QR code
- Returns a
LoginQrCodeobject with:getQrCodeLink(): Thetg://login?token=...URLisExpired(): Check if QR code is still validgetExpiry(): Get expiration timestamp
QR codes expire after a certain period. Check
isExpired() and regenerate if needed.Login States
MadelineProto tracks the authentication state using constants fromAPI.php:56-90:
No authentication has been performed
Waiting for SMS/Telegram login code
Phone number not registered, signup required
Waiting for 2FA password
Successfully authenticated
Logged out, session will be deleted
Authorization Import/Export
Export Authorization
Export the authorization key for backup or multi-DC scenarios:Wrappers/Login.php:301, this returns:
$dcId: The datacenter ID$authKey: The authorization key (keep this secure!)
Import Authorization
Import a previously exported authorization:2FA Management
Update two-factor authentication settings:Logout
Properly log out and invalidate the session:Wrappers/Login.php:162):
- Calls
auth.logOuton the API - Sets login state to
API::LOGGED_OUT - Stops the event handler if running
- Stops the IPC server
Complete Login Example
Here’s a complete user login flow:Next Steps
Event Handlers
Set up event handlers to process updates
Async Operations
Understand asynchronous programming in MadelineProto