phpbotgram

InlineKeyboardBuilder extends KeyboardBuilder
in package

FinalYes

Fluent builder for `InlineKeyboardMarkup`.

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

Tags
extends

Table of Contents

Constants

MAX_BUTTONS  : int = 100
Maximum total buttons for inline keyboards (Telegram limit: 100).
MAX_WIDTH  : int = 8
Maximum buttons per row for inline keyboards (Telegram limit: 8).
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 an `InlineKeyboardMarkup` DTO.
attach()  : static
Concatenate another builder's markup onto this one.
button()  : static
Add a fully-specified `InlineKeyboardButton` to the markup by flowing it through `add()`.
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 an `InlineKeyboardBuilder` from an existing `InlineKeyboardMarkup`.
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 inline keyboards (Telegram limit: 100).

public int MAX_BUTTONS = 100

MAX_WIDTH

Maximum buttons per row for inline keyboards (Telegram limit: 8).

public int MAX_WIDTH = 8

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

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 fully-specified `InlineKeyboardButton` to the markup by flowing it through `add()`.

public button(string $text[, string|null $url = null ][, null|CallbackData|string $callbackData = null ][, WebAppInfo|null $webApp = null ][, LoginUrl|null $loginUrl = null ][, string|null $switchInlineQuery = null ][, string|null $switchInlineQueryCurrentChat = null ][, SwitchInlineQueryChosenChat|null $switchInlineQueryChosenChat = null ][, CopyTextButton|null $copyText = null ][, CallbackGame|null $callbackGame = null ][, bool|null $pay = null ][, string|null $iconCustomEmojiId = null ][, string|null $style = null ]) : static

Convenience factory that mirrors upstream's InlineKeyboardBuilder.button(). When $callbackData is a CallbackData instance it is packed to its wire string via CallbackData::pack().

Parameters
$text : string
$url : string|null = null
$callbackData : null|CallbackData|string = null
$webApp : WebAppInfo|null = null
$loginUrl : LoginUrl|null = null
$switchInlineQuery : string|null = null
$switchInlineQueryCurrentChat : string|null = null
$switchInlineQueryChosenChat : SwitchInlineQueryChosenChat|null = null
$copyText : CopyTextButton|null = null
$callbackGame : CallbackGame|null = null
$pay : bool|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>

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