Skip to main content
The InlineKeyboard class simplifies building inline keyboards (interactive button grids attached to messages). Unlike custom keyboards, inline keyboards appear directly below messages and trigger callback queries or open URLs when pressed.

Constructor

Creates a new InlineKeyboard instance.
InlineKeyboardButton[][]
Optional two-dimensional array of inline keyboard buttons. If not provided, starts with an empty keyboard.

Example

Properties

InlineKeyboardButton[][]
The two-dimensional array of buttons that makes up the inline keyboard (read-only).

Button Methods

These methods add buttons to the keyboard and return this for chaining.

text

Adds a callback query button that sends data back to your bot when pressed.
string | object
required
The button text to display
string
Callback data to send back to your bot. Defaults to the button text if omitted.
Example:

url

Adds a button that opens a URL when pressed.
string | object
required
The button text to display
string
required
HTTP or tg:// URL to open. Can use tg://user?id=<user_id> to mention users.
Example:

webApp

Adds a button that launches a Web App.
string | object
required
The button text to display
string | WebAppInfo
required
HTTPS URL of the Web App or WebAppInfo object
Example:

login

Adds a login button for Telegram Login Widget.
string | object
required
The button text to display
string | LoginUrl
required
HTTPS URL for automatic authorization or LoginUrl object with additional options
Example:

switchInline

Adds a button that starts an inline query in a selected chat.
string | object
required
The button text to display
string
Inline query string to prefill. Defaults to empty string.
Example:

switchInlineCurrent

Adds a button that starts an inline query in the current chat.
string | object
required
The button text to display
string
Inline query string to prefill. Defaults to empty string.
Example:

switchInlineChosen

Adds a button that starts an inline query with chat type restrictions.
string | object
required
The button text to display
SwitchInlineQueryChosenChat
Object describing which chats can be picked
Example:

copyText

Adds a button that copies text to the clipboard when pressed.
string | object
required
The button text to display
string | CopyTextButton
required
Text to copy to clipboard
Example:

game

Adds a game button. Must be the first button in the first row.
string | object
required
The button text to display
Example:

pay

Adds a payment button. Must be the first button in the first row and can only be used in invoice messages.
string | object
required
The button text to display. Substrings ”⭐” and “XTR” will be replaced with a Telegram Star icon.
Example:

Styling Methods

These methods modify the last added button.

style

Applies a style to the last added button.
'primary' | 'success' | 'danger'
required
Button style: 'primary' (blue), 'success' (green), or 'danger' (red)
Example:

danger

Applies danger (red) style. Alias for .style('danger').

success

Applies success (green) style. Alias for .style('success').

primary

Applies primary (blue) style. Alias for .style('primary').

icon

Adds a custom emoji icon to the last added button.
string
required
Unique identifier of the custom emoji
Example:

Layout Methods

row

Adds a line break to start a new row of buttons.
InlineKeyboardButton[]
Optional buttons to add to the new row
Example:

add

Adds pre-constructed button objects to the current row.
InlineKeyboardButton[]
required
Button objects to add

Transformation Methods

toTransposed

Creates a new inline keyboard with rows and columns flipped.
Example:

toFlowed

Creates a new inline keyboard with buttons reflowed into a given number of columns.
number
required
Maximum number of buttons per row
object
Example:

clone

Creates a deep copy of the inline keyboard.

append

Appends buttons from other inline keyboards.
Array
required
Inline keyboards or button arrays to append

Static Methods

InlineKeyboard.text

Creates a callback button without adding it to a keyboard.

InlineKeyboard.url

Creates a URL button without adding it to a keyboard.

InlineKeyboard.from

Creates an inline keyboard from a two-dimensional button array.
InlineKeyboardButton[][] | InlineKeyboard
required
Button array or existing keyboard to copy
Example:
All other button methods also have static equivalents.

Complete Example

See Also