Sometimes it might be nice to get user input via predefined options. This is where a reply keyboard comes in handy. Reply keyboards allow you to show a "keyboard" of sorts directly below the message field. Inline keyboards are keyboards which are directly attached to a message. Both are useful in different scenarios, and both come with a conventint
Reply keyboards are created using the
ReplyKeyboardMarkup class. They are great for when you ask a question and want a response from a small predefined set of options. The buttons will be large and appear right below the user's message input field.
They are also capable of a few things that inline keyboards are not. For example: requesting contact information, requesting a user's location, and prompting the user to create a poll. For a standard
KeyboardButton without one of those options, the text that's on the button will be sent by the user on click.
Thanks to the
ReplyKeyboardMarkup::Builder class, creating reply keyboards is a sinch:
Telegram also allows the creation of inline keyboards. Inline keyboards, as the name states, are displayed inline right below the message they're attached to, rather than being attached below the message area. When creating an inline keyboard you have to listen for a button press and then act on it. This can be done with the
CallbackQueryHandler and the
OnCallbackQuery annotation. Let's take a look:
And you'll end up with this: