phpbotgram

ReplyKeyboardBuilder extends KeyboardBuilder
in package

FinalYes

Fluent builder for `ReplyKeyboardMarkup`.

Port of upstream aiogram/utils/keyboard.pyReplyKeyboardBuilder class.

Tags
extends

Table of Contents

Constants

MAX_BUTTONS  : int = 300
Maximum total buttons for reply keyboards (Telegram limit: 300).
MAX_WIDTH  : int = 10
Maximum buttons per row for reply keyboards.
MIN_WIDTH  : int = 1
Minimum row width.

Properties

$buttonType  : string
$markup  : array<int, array<int, T>>
Internal two-dimensional markup storage.

Methods

__construct()  : mixed
add()  : static
Flow buttons into rows. When `MAX_WIDTH` is 0, each call appends a new row containing all the given buttons (no row-fill; matches upstream `keyboard.py` behaviour for `max_width == 0`). When `MAX_WIDTH` is positive, the last incomplete row is filled first, then remaining buttons are chunked into full rows of that width.
adjust()  : static
Reshape all buttons into rows of the given widths. The last size is repeated for any remaining buttons (upstream `repeat=False` default).
adjustRepeating()  : static
Reshape all buttons into rows of the given widths, cycling through the size list (upstream `repeat=True` variant).
asMarkup()  : InlineKeyboardMarkup|ReplyKeyboardMarkup
Wrap the current markup in a `ReplyKeyboardMarkup` DTO.
attach()  : static
Concatenate another builder's markup onto this one.
button()  : static
Add a `KeyboardButton` by specifying its fields directly.
buttons()  : Generator<int, T>
Flatten all buttons into a single iterator.
copy()  : self
Create a deep-copied clone of this builder.
export()  : array<int, array<int, T>>
Return a deep copy of the internal markup.
fromMarkup()  : self
Create a `ReplyKeyboardBuilder` from an existing `ReplyKeyboardMarkup`.
row()  : static
Append buttons as one or more new rows.
validateButton()  : void
Assert that a button is an instance of `$buttonType`.
validateMarkup()  : void
Assert that every row in a markup array is a list of valid buttons, and that the total button count does not exceed `MAX_BUTTONS`.

Constants

MAX_BUTTONS

Maximum total buttons for reply keyboards (Telegram limit: 300).

public int MAX_BUTTONS = 300

MAX_WIDTH

Maximum buttons per row for reply keyboards.

public int MAX_WIDTH = 10

Matches upstream aiogram/utils/keyboard.py:374 (max_width: int = 10).

Properties

$markup

Internal two-dimensional markup storage.

protected array<int, array<int, T>> $markup = []

Methods

add()

Flow buttons into rows. When `MAX_WIDTH` is 0, each call appends a new row containing all the given buttons (no row-fill; matches upstream `keyboard.py` behaviour for `max_width == 0`). When `MAX_WIDTH` is positive, the last incomplete row is filled first, then remaining buttons are chunked into full rows of that width.

public add(T ...$buttons) : static
Parameters
$buttons : T
Return values
static

adjust()

Reshape all buttons into rows of the given widths. The last size is repeated for any remaining buttons (upstream `repeat=False` default).

public adjust(int ...$sizes) : static

Pass no arguments to default to [MAX_WIDTH].

Parameters
$sizes : int
Return values
static

adjustRepeating()

Reshape all buttons into rows of the given widths, cycling through the size list (upstream `repeat=True` variant).

public adjustRepeating(int ...$sizes) : static
Parameters
$sizes : int
Return values
static

asMarkup()

Wrap the current markup in a `ReplyKeyboardMarkup` DTO.

public asMarkup([null|bool $isPersistent = null ][, null|bool $resizeKeyboard = null ][, null|bool $oneTimeKeyboard = null ][, null|string $inputFieldPlaceholder = null ][, null|bool $selective = null ]) : InlineKeyboardMarkup|ReplyKeyboardMarkup
Parameters
$isPersistent : null|bool = null

Show the keyboard persistently.

$resizeKeyboard : null|bool = null

Request clients to resize the keyboard.

$oneTimeKeyboard : null|bool = null

Hide the keyboard after a button is pressed.

$inputFieldPlaceholder : null|string = null

Placeholder text for the input field.

$selective : null|bool = null

Show keyboard to specific users only.

Return values
InlineKeyboardMarkup|ReplyKeyboardMarkup

attach()

Concatenate another builder's markup onto this one.

public attach(KeyboardBuilder<string|int, T$other) : static

Both builders must have the same $buttonType — a mismatch throws InvalidArgumentException to mirror upstream's type validation.

Parameters
$other : KeyboardBuilder<string|int, T>
Tags
throws
InvalidArgumentException

When the button types do not match.

Return values
static

button()

Add a `KeyboardButton` by specifying its fields directly.

public button(string $text[, 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 ][, string|null $iconCustomEmojiId = null ][, string|null $style = null ]) : static

Mirrors upstream's ReplyKeyboardBuilder.button().

Parameters
$text : string
$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
$iconCustomEmojiId : string|null = null
$style : string|null = null
Return values
static

buttons()

Flatten all buttons into a single iterator.

public buttons() : Generator<int, T>
Return values
Generator<int, T>

copy()

Create a deep-copied clone of this builder.

public copy() : self
Return values
self

export()

Return a deep copy of the internal markup.

public export() : array<int, array<int, T>>
Return values
array<int, array<int, T>>

row()

Append buttons as one or more new rows.

public row(array<int, T$buttons[, int|null $width = null ]) : static

When $width is null, the effective width defaults to MAX_WIDTH (upstream keyboard.py parity: width = self.max_width). When MAX_WIDTH is 0 and $width is null, all buttons go into a single row (no width limit). An explicit $width > 0 overrides the default but is capped to MAX_WIDTH when that constant is positive.

Parameters
$buttons : array<int, T>
$width : int|null = null
Return values
static

validateButton()

Assert that a button is an instance of `$buttonType`.

protected validateButton(object $button) : void
Parameters
$button : object
Tags
throws
InvalidArgumentException

validateMarkup()

Assert that every row in a markup array is a list of valid buttons, and that the total button count does not exceed `MAX_BUTTONS`.

protected validateMarkup(array<int, array<int, T>> $markup) : void
Parameters
$markup : array<int, array<int, T>>
Tags
throws
InvalidArgumentException
On this page

Search results