User
extends TelegramObject
in package
uses
UserShortcuts
This object represents a Telegram user or bot.
Source: https://core.telegram.org/bots/api#user
Table of Contents
Properties
- $addedToAttachmentMenu : bool|null
- $allowsUsersToCreateTopics : bool|null
- $bot : Bot|null
- $canConnectToBusiness : bool|null
- $canJoinGroups : bool|null
- $canManageBots : bool|null
- $canReadAllGroupMessages : bool|null
- $firstName : string
- $hasMainWebApp : bool|null
- $hasTopicsEnabled : bool|null
- $id : int
- $isBot : bool
- $isPremium : bool|null
- $languageCode : string|null
- $lastName : string|null
- $supportsGuestQueries : bool|null
- $supportsInlineQueries : bool|null
- $supportsJoinRequestQueries : bool|null
- $username : string|null
Methods
- __construct() : mixed
- as_() : static
- Alias of withBot() for grep-translating aiogram code that uses obj.as_(bot).
- fullName() : string
- The user's full display name: `firstName lastName` for a user with both names, otherwise just `firstName`. Whitespace is normalised so a missing `lastName` doesn't leak a trailing space.
- getProfileAudios() : GetUserProfileAudios
- getProfilePhotos() : GetUserProfilePhotos
- mentionHtml() : string
- HTML-formatted user mention: an `<a href="tg://user?id=…">name</a>` link Telegram clients render as a tappable mention.
- mentionMarkdown() : string
- Markdown-formatted user mention: `[name](tg://user?id=…)`.
- withBot() : static
- Returns a clone of $this with $bot rebound recursively. Walks every public property; nested `BotContextController` instances are rebound via their own `withBot`, arrays (including nested arrays of arbitrary depth — e.g.
Properties
$addedToAttachmentMenu read-only
public
bool|null
$addedToAttachmentMenu
= null
$allowsUsersToCreateTopics read-only
public
bool|null
$allowsUsersToCreateTopics
= null
$bot read-only
public
Bot|null
$bot
= null
$canConnectToBusiness read-only
public
bool|null
$canConnectToBusiness
= null
$canJoinGroups read-only
public
bool|null
$canJoinGroups
= null
$canManageBots read-only
public
bool|null
$canManageBots
= null
$canReadAllGroupMessages read-only
public
bool|null
$canReadAllGroupMessages
= null
$firstName read-only
public
string
$firstName
$hasMainWebApp read-only
public
bool|null
$hasMainWebApp
= null
$hasTopicsEnabled read-only
public
bool|null
$hasTopicsEnabled
= null
$id read-only
public
int
$id
$isBot read-only
public
bool
$isBot
$isPremium read-only
public
bool|null
$isPremium
= null
$languageCode read-only
public
string|null
$languageCode
= null
$lastName read-only
public
string|null
$lastName
= null
$supportsGuestQueries read-only
public
bool|null
$supportsGuestQueries
= null
$supportsInlineQueries read-only
public
bool|null
$supportsInlineQueries
= null
$supportsJoinRequestQueries read-only
public
bool|null
$supportsJoinRequestQueries
= null
$username read-only
public
string|null
$username
= null
Methods
__construct()
public
__construct(int $id, bool $isBot, string $firstName[, string|null $lastName = null ][, string|null $username = null ][, string|null $languageCode = null ][, bool|null $isPremium = null ][, bool|null $addedToAttachmentMenu = null ][, bool|null $canJoinGroups = null ][, bool|null $canReadAllGroupMessages = null ][, bool|null $supportsGuestQueries = null ][, bool|null $supportsInlineQueries = null ][, bool|null $canConnectToBusiness = null ][, bool|null $hasMainWebApp = null ][, bool|null $hasTopicsEnabled = null ][, bool|null $allowsUsersToCreateTopics = null ][, bool|null $canManageBots = null ][, bool|null $supportsJoinRequestQueries = null ][, Bot|null $bot = null ]) : mixed
Parameters
- $id : int
- $isBot : bool
- $firstName : string
- $lastName : string|null = null
- $username : string|null = null
- $languageCode : string|null = null
- $isPremium : bool|null = null
- $addedToAttachmentMenu : bool|null = null
- $canJoinGroups : bool|null = null
- $canReadAllGroupMessages : bool|null = null
- $supportsGuestQueries : bool|null = null
- $supportsInlineQueries : bool|null = null
- $canConnectToBusiness : bool|null = null
- $hasMainWebApp : bool|null = null
- $hasTopicsEnabled : bool|null = null
- $allowsUsersToCreateTopics : bool|null = null
- $canManageBots : bool|null = null
- $supportsJoinRequestQueries : bool|null = null
- $bot : Bot|null = null
as_()
Alias of withBot() for grep-translating aiogram code that uses obj.as_(bot).
public
as_(Bot|null $bot) : static
IMPORTANT: behaves DIFFERENTLY from upstream — upstream mutates self.bot in place and returns self. The PHP port can't mutate readonly, so this returns a clone. Callers must reassign: $msg = $msg->as($bot).
Parameters
- $bot : Bot|null
Return values
staticfullName()
The user's full display name: `firstName lastName` for a user with both names, otherwise just `firstName`. Whitespace is normalised so a missing `lastName` doesn't leak a trailing space.
public
fullName() : string
Return values
stringgetProfileAudios()
public
getProfileAudios([int|null $offset = null ][, int|null $limit = null ]) : GetUserProfileAudios
Parameters
- $offset : int|null = null
- $limit : int|null = null
Return values
GetUserProfileAudiosgetProfilePhotos()
public
getProfilePhotos([int|null $offset = null ][, int|null $limit = null ]) : GetUserProfilePhotos
Parameters
- $offset : int|null = null
- $limit : int|null = null
Return values
GetUserProfilePhotosmentionHtml()
HTML-formatted user mention: an `<a href="tg://user?id=…">name</a>` link Telegram clients render as a tappable mention.
public
mentionHtml([string|null $name = null ]) : string
The display label is HTML-escaped with htmlspecialchars (default
ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5 flags) so a maliciously
crafted name can't break out of the <a> element. Pre-escape:
passing Foo<Bar> as the label produces Foo<Bar> inside
the anchor text.
Parameters
- $name : string|null = null
Return values
stringmentionMarkdown()
Markdown-formatted user mention: `[name](tg://user?id=…)`.
public
mentionMarkdown([string|null $name = null ]) : string
The label is passed through verbatim — Telegram's Markdown parser
tolerates a wider character set inside […] than HTML does inside
<a>, and aiogram's upstream helper takes the same approach. A
caller passing untrusted input should escape the few reserved
Markdown characters ([, ], \) themselves.
Parameters
- $name : string|null = null
Return values
stringwithBot()
Returns a clone of $this with $bot rebound recursively. Walks every public property; nested `BotContextController` instances are rebound via their own `withBot`, arrays (including nested arrays of arbitrary depth — e.g.
public
withBot(Bot|null $bot) : static
list<list<KeyboardButton>>) are walked element-wise. Plain values
(scalars, DateTime, enums, InputFile etc.) pass through untouched.
Mirrors upstream pydantic model_validate(context={"bot": bot}) (aiogram
ContextController.as_/model_dump_json+model_validate).
Scope note: PHP 8.5 treats public readonly as effectively
public protected(set) readonly for clone-with — only code running with
a scope in the property's declaring class hierarchy (declaring class plus
its ancestors and descendants) can use clone($obj, ['x' => ...]) against
it. Because this method lives on BotContextController and every
TelegramObject/TelegramMethod subclass extends it, the walker's
clone($this, [...]) call legally rewrites subclass-declared readonly
slots like Message::$chat. External callers cannot use the same syntax
— they must funnel through this method.
Parameters
- $bot : Bot|null