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
- Callback
- URL
- Web App
- Switch Inline
Dynamic Keyboards
Generate keyboards based on data:Removing Keyboards
Remove a custom keyboard:Handling Callbacks
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.