KeyboardButton
extends MutableTelegramObject
in package
This object represents one button of the reply keyboard. At most one of the fields other than text, icon_custom_emoji_id, and style must be used to specify the type of the button. For simple text buttons, String can be used instead of this object to specify the button text.
Source: https://core.telegram.org/bots/api#keyboardbutton
Table of Contents
Properties
- $bot : Bot|null
- $iconCustomEmojiId : string|null
- $requestChat : KeyboardButtonRequestChat|null
- $requestContact : bool|null
- $requestLocation : bool|null
- $requestManagedBot : KeyboardButtonRequestManagedBot|null
- $requestPoll : KeyboardButtonPollType|null
- $requestUsers : KeyboardButtonRequestUsers|null
- $style : string|null
- $text : string
- $webApp : WebAppInfo|null
Methods
- __construct() : mixed
- as_() : static
- Alias of withBot() for grep-translating aiogram code that uses obj.as_(bot).
- 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
$bot read-only
public
Bot|null
$bot
= null
$iconCustomEmojiId read-only
public
string|null
$iconCustomEmojiId
= null
$requestChat read-only
public
KeyboardButtonRequestChat|null
$requestChat
= null
$requestContact read-only
public
bool|null
$requestContact
= null
$requestLocation read-only
public
bool|null
$requestLocation
= null
$requestManagedBot read-only
public
KeyboardButtonRequestManagedBot|null
$requestManagedBot
= null
$requestPoll read-only
public
KeyboardButtonPollType|null
$requestPoll
= null
$requestUsers read-only
public
KeyboardButtonRequestUsers|null
$requestUsers
= null
$style read-only
public
string|null
$style
= null
$text read-only
public
string
$text
$webApp read-only
public
WebAppInfo|null
$webApp
= null
Methods
__construct()
public
__construct(string $text[, string|null $iconCustomEmojiId = null ][, string|null $style = null ][, KeyboardButtonRequestUsers|null $requestUsers = null ][, KeyboardButtonRequestChat|null $requestChat = null ][, KeyboardButtonRequestManagedBot|null $requestManagedBot = null ][, bool|null $requestContact = null ][, bool|null $requestLocation = null ][, KeyboardButtonPollType|null $requestPoll = null ][, WebAppInfo|null $webApp = null ][, Bot|null $bot = null ]) : mixed
Parameters
- $text : string
- $iconCustomEmojiId : string|null = null
- $style : string|null = null
- $requestUsers : KeyboardButtonRequestUsers|null = null
- $requestChat : KeyboardButtonRequestChat|null = null
- $requestManagedBot : KeyboardButtonRequestManagedBot|null = null
- $requestContact : bool|null = null
- $requestLocation : bool|null = null
- $requestPoll : KeyboardButtonPollType|null = null
- $webApp : WebAppInfo|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
staticwithBot()
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