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 returnthis 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.
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.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
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
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.
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.
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
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
game
Adds a game button. Must be the first button in the first row.string | object
required
The button text to display
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.
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)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
Layout Methods
row
Adds a line break to start a new row of buttons.InlineKeyboardButton[]
Optional buttons to add to the new row
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.toFlowed
Creates a new inline keyboard with buttons reflowed into a given number of columns.number
required
Maximum number of buttons per row
object
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
Complete Example
See Also
- Keyboard - Custom reply keyboards
- Inline Keyboards Guide - Complete documentation
- Telegram Bot API: InlineKeyboardMarkup