Skip to main content

User Methods

The users namespace provides methods for working with users in Telegram.

Accessing User Methods

// In EventHandler
$userInfo = $this->users->getFullUser(['id' => $userId]);

// In API instance
$userInfo = $MadelineProto->users->getFullUser(['id' => $userId]);

Getting User Information

getFullUser

Get full information about a user.
id
string|int
required
User ID, username, or user object
Returns: Full user information including:
  • Basic profile data (name, username, phone)
  • Bio and about text
  • Profile photo
  • Privacy settings
  • Verification status
  • Premium status
$user = $this->users->getFullUser(['id' => '@username']);

echo "Name: " . $user['users'][0]['first_name'] . "\n";
echo "Username: @" . $user['users'][0]['username'] . "\n";
echo "Bio: " . $user['full_user']['about'] . "\n";

Helper Methods

MadelineProto provides several helper methods for user information through the API class:

getInfo

Get basic user information (lightweight).
$info = $this->getInfo($peer);

// Returns:
// - 'type' => 'user' | 'bot' | 'chat' | 'supergroup' | 'channel'
// - 'id' => numeric ID
// - 'user_id' => Telegram user ID
// - 'first_name', 'last_name', 'username'
// - 'bot' => true/false
This method is faster than getFullUser for basic information.

getSelf

Get information about the currently logged-in user.
$me = $this->getSelf();

if ($me['bot']) {
    echo "Logged in as bot: @" . $me['username'];
} else {
    echo "Logged in as user: " . $me['first_name'];
}

getId

Extract the numeric user ID from various formats.
// From username
$id = $this->getId('@username');

// From user object
$id = $this->getId($user);

// From bot API style ID
$id = $this->getId(-1001234567890);

User Status

Checking Online Status

$fullUser = $this->users->getFullUser(['id' => $userId]);
$status = $fullUser['users'][0]['status'];

match ($status['_']) {
    'userStatusOnline' => "Online until " . date('H:i', $status['expires']),
    'userStatusOffline' => "Last seen " . date('Y-m-d H:i', $status['was_online']),
    'userStatusRecently' => "Last seen recently",
    'userStatusLastWeek' => "Last seen last week",
    'userStatusLastMonth' => "Last seen last month",
    default => "Unknown status"
};

User Profile Photos

Getting Profile Photos

$photos = $this->photos->getUserPhotos([
    'user_id' => $userId,
    'offset' => 0,
    'max_id' => 0,
    'limit' => 10
]);

foreach ($photos['photos'] as $photo) {
    // Download profile photo
    $this->downloadToDir($photo, '/path/to/dir/');
}

Common Use Cases

Check if User is Bot

if ($this->isBot($peer)) {
    echo "This is a bot account";
}

Get User’s Username

$info = $this->getInfo($userId);
$username = $info['username'] ?? null;

if ($username) {
    echo "Username: @$username";
} else {
    echo "User has no username";
}

Check Premium Status

$fullUser = $this->users->getFullUser(['id' => $userId]);
$isPremium = $fullUser['users'][0]['premium'] ?? false;

if ($isPremium) {
    echo "This user has Telegram Premium";
}

Best Practices

Don’t call getFullUser repeatedly for the same user. Cache the results and refresh periodically.
When you only need basic information like username or ID, use getInfo() instead of getFullUser().
Some users may have restricted their profile information. Always check if fields exist before accessing them.
Avoid making too many user lookup requests in quick succession to prevent flood waits.

See Also

Build docs developers (and LLMs) love