Skip to main content
Keyboards are one of the most powerful features for bot interaction. grammY provides two types: custom keyboards (shown below the message input) and inline keyboards (shown below messages).

Custom Keyboards

Custom keyboards replace the user’s system keyboard:

Building Custom Keyboards

Keyboard Options

() => Keyboard
Requests clients to resize the keyboard vertically for optimal fit
() => Keyboard
Keeps the keyboard visible even when the user sends a message
() => Keyboard
Shows the keyboard only to specific users (those mentioned in the message or replying to the bot)
() => Keyboard
Hides the keyboard after the user presses a button
(text: string) => Keyboard
Sets the placeholder text shown in the input field

Inline Keyboards

Inline keyboards are attached to messages and trigger callback queries:

Building Inline Keyboards

Button Types

Sends a callback query to your bot when pressed.

Dynamic Keyboards

Generate keyboards based on data:

Removing Keyboards

Remove a custom keyboard:

Handling Callbacks

Always call answerCallbackQuery() within 30 seconds or Telegram will show an error to the user.

Best Practices

Keep Labels Short

Button labels should be concise—Telegram truncates long text.

Use Meaningful Callbacks

Use descriptive callback data to make your code maintainable.

Provide Feedback

Always call answerCallbackQuery() to acknowledge button presses.

Update Messages

Use editMessageText() or editMessageReplyMarkup() to update inline keyboards.

Examples

Pagination

Confirmation Dialog

See Also